-1
我希望在用戶選擇「VIEW」或「BID」後再次打開菜單..我將如何那樣做沒有無限循環?我將菜單設置爲自己的功能,然後在我的「主」功能中調用它。選擇一個菜單選項後,再次打印菜單..選擇選項後,「do while」循環無限
int menu() {
char sel[6];
printf("Welcome to the Silent Auction!\n");
printf("Please make a selection from the following:\n");
printf("View Auction [VIEW]\n");
printf("Bid on Auction [BID]\n");
printf("Close Auction [CLOSE]\n");
return;
}
menu();
char sel[6];
scanf("%s", &sel);
do {
if (strcmp("VIEW", sel) == 0) {
...
}
if (strcmp("BID", sel) == 0) {
printf("Which auction would you like to bid on?\n");
scanf("%d", &choice);
if ...
} else {
...
} printf("How much would you like to bid?\n");
scanf("%f", &user_bid);
if ...
else
cur_bid[choice] += user_bid;
}
if (strcmp("CLOSE", sel) == 0) {
for...
}
} while (sel != "CLOSE");
return 0;
}
當用戶輸入「VIEW」的作品,但如果他們選擇另一option..say「BID」或「關閉「,我的if語句不工作。它只是終止。 – user2251238 2013-04-07 03:01:21
確定適用於VIEW和BID。但是,當我選擇「關閉」程序不通過我的if語句爲此..它終止 – user2251238 2013-04-07 03:14:19
@ user2251238 ..請檢查我更新的答案在哪裏我使用關閉標誌。 – Ganesh 2013-04-07 03:22:20