简体   繁体   中英

Restaurant Program, when repeating, skips the first inputs

new to programming here :3 (Don't check my profile, I actually only know C, for now...)

I need help here, I dunno what's causing the problem, but whenever I repeat the program, it skips asking for a replacement value in

char C1.name

in function

void Name()
{
p("ENTER NAME: ");
gets(C1.name);
p("CONTACT DETAILS: ");
s("%d", &C1.cont_no);
}

in my Program

#include <stdio.h>
#include <windows.h>
#define p printf
#define s scanf

void Name();
void Order();
void Total();
void Receipt();
char Repeat();

/* CUSTOMER DETAILS */
struct CustomerOrder
{
    char name[50];
    long int cont_no;
    int qty;
    float price, total;
} C1;

main()
{
    char cont;

    /* Program Process... */

    do{
        Name();
        Order();
        Total();
        Receipt();

        cont = Repeat();
        }while(cont == 'Y');
}

void Name()
{
    /* ENTER NAME AND CONTACT DETAILS */
    p("ENTER NAME: ");
    gets(C1.name);
    p("CONTACT DETAILS: ");
    s("%d", &C1.cont_no);
}

void Order()
{
    /* ENTER ORDERS */
    p("HOW MANY ORDERS: ");
    s("%d", &C1.qty);

    C1.price = 59.99;
}

void Total()
{
    /* TOTAL */
    C1.total = C1.price * C1.qty;

    p("TOTAL IS: %.2f", C1.total);
    system("pause");
} 

void Receipt()
{
    system("cls");
    /*PRINTED RECEIPT SAMPLE */
    p("NAME IS: %s\n", C1.name);
    p("CONTACT DETAILS: %d\n", C1.cont_no);
    p("QTY: %d\n", &C1.qty);
    p("PRICE EACH: %.2f\n", C1.price);
    p("TOTAL PAYOUT: %.2f\n", C1.total);
}

char Repeat()
{
    /* ASKS USER TO REPEAT PROGRAM, THEN RETURN VALUE TO BE USED BY function 
    main */
    char repeat;

    p("REPEAT?: ");
    s("%s", &repeat);

    return repeat;
}

There may be other problems you would probably notice (which I dunno if there are, but I would like it NOT to skip the Name part and stuff...

You only want to get a character when asking the user to repeat so change

s("%s", &repeat);

to

              s(" %c", &repeat);

if you add a space ^ you will skip the \\n that you entered previously.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM