[英]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...)在这里编程的新手:3(不要检查我的个人资料,我实际上只知道 C,现在......)
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字符 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.如果您添加一个空格 ^ 您将跳过您之前输入的 \\n。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.