【发布时间】:2014-03-13 06:47:17
【问题描述】:
问题是当我输入除y 或n 之外的任何字符时,它会显示此消息两次而不是一次)
This program is 'Calculator'
Do you want to continue?
Type 'y' for yes or 'n' for no
invalid input
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main ()
{
//program
//first to get two numbers
//second to get choice
int x=0,y=0,n=0;
char choice;
//clrscr(); does no work in devc++
system("cls"); //you may also use system("clear");
while(x==0)
{
puts("\t\tThis program is 'Calculator'\n\n");
puts("Do you want to continue?");
puts("Type 'y' for yes or 'n' for no ");
scanf("%c",&choice);
x++;
if(choice=='y')
{
y++;
puts("if this worked then we would continue to calculate the 2 no");
}
else if(choice=='n')
exit(0);
else
{
puts("invalid input");
x=0;
}
}
getch();
}
`
【问题讨论】:
-
好吧,您基本上是在说“无效输入”,然后再次提示它们,这似乎是基于您编写的代码的预期行为。
-
但对我来说它提示两次而不是一次
标签: c while-loop dev-c++