while循环中加switch问题

来源:百度知道 编辑:UC知道 时间:2024/09/23 10:16:26
#include "stdio.h"
star1()
{
printf("\t **************");
}
star2()
{
printf(" *****************************");
}
main()
{
char a;
printf("\t\tMain nenu\n\n");
star2();
printf("\n");
star1();
puts("\n");
printf(" 1.Input student's score.\n");
printf(" 2.Consult student's score.\n");
printf(" 3.Prints student's score.\n");
printf(" 0.Quit system.\n");
star1();
printf("\n");
star2();
printf("\n");
printf("Input you choices:\n");
a=getchar();

while(1)
{
switch(a)
{
case '1':printf("Please type in:\n");
break;
case '

问题主要出现在:
B: printf("Enter another choice,Please type in.\n");
a=getchar();
当你输入一个a时,程序本身相当于是执行了两次,第一次执行的是你输入的a,而第二次执行的是\n
可以改为(个人不提倡用scanf):预处理命令添加如下:
#include "iostream"
using namespace std;
在将B: printf("Enter another choice,Please type in.\n");
a=getchar(); 改为:
B: printf("Enter another choice,Please type in.\n");
cin>>a;

以上纯属个人见解与个人习惯。。。