我對 C 編程很陌生,我對代碼如何提示輸入有疑問。我需要輸入陳述句下的輸入一一來。現在提示的輸出方式是:
To add a new task enter the details below
Name of Task: Science
然后所有其他輸入作為一個組來
Category of Task:
Information about task:
Due Date of Task:
Status of Task
TD = To-Do
IP = In Progress
CT = Completed Task
Enter Status:
但我想先詢問任務的名稱,一旦我輸入該資訊,它應該詢問類別例如:
To add a new task enter the details below
Name of Task:
這是我的代碼:
#include<stdio.h>
int main() {
char main_choice;
printf("Welcome to your Task Management System\n");
printf("What would you like to do today?\n A: Add New Task\n B: View Task \n C: Manage Tasks\n");
printf("\nEnter your choice:");
scanf("%c", &main_choice);
if (main_choice == 'A'){
char name;
char category;
char info;
char date;
char status;
printf("\nTo Add a new task enter the details below\n");
printf("Name of Task:");
scanf(" %c", &name);
printf("\nCategory of Task:");
scanf(" %c", &category);
printf("Information about task:");
scanf(" %c", &info);
printf("Due Date of Task:");
scanf(" %c", &date);
printf("Status of Task\nTD = To-Do\nIP = In Progress\nCT = Completed Task\n Enter Status:");
scanf(" %c", &status);
}
return 0;
}
uj5u.com熱心網友回復:
在 C 中使用 scanf 時,您應該在 %c 之前放置一個空格,如下所示:
scanf(" %c", &name);
需要在 %c 之前放置空格以跳過緩沖存盤器中的空白。這樣 %c 匹配給定的字符而不是空格字符。
uj5u.com熱心網友回復:
#include<stdio.h>
int main() {
char main_choice;
printf("Welcome to your Task Management Sytem\n");
printf("What would you like to do today?\n A: Add New Task\n B: View Task \n C: Manage Tasks\n");
printf("\nEnter your choice:");
scanf("%c", &main_choice);
if (main_choice == 'A'){
char name[20];
char category[20];
char info[20];
char date[20];
char status[20];
printf("\nTo Add a new task enter the details below\n");
printf("Name of Task:");
scanf(" %s", &name);
printf("\nCategory of Task:");
scanf(" %s", &category);
printf("\nInformation about task:");
scanf(" %s", &info);
printf("\nDue Date of Task:");
scanf(" %s", &date);
printf("\nStatus of Task\nTD = To-Do\nIP = In Progress\nCT = Completed Task\n Enter Status:");
scanf(" %s", &status);
}
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/469126.html
標籤:C
上一篇:通過陣列物件javascript訪問所需資訊時遇到問題
下一篇:C正則運算式不匹配