c++简单的程序,为什么不运行第二个输入语句?
这个问题是这几天在taikongxinke发的帖子上看到的,但是发现后面还有点问题不知道为什么~
这个程序在输入"6:30"后,将不会执行第二句输入语句,直接跳过输出莫名其妙的答案,这个是为什么?
#include <iostream >
using namespace std;
int main()
{
int t=0,t1=0,t2=0,hour1,hour2,minute1,minute2,a;
cout <<"Please input the first time:";
cin >>hour1>>a>>minute1;
if((hour1 <0 )&&(hour1 >23)||(minute1 <0)&&(minute1 >59))
cout <<"Please input the hour from 0 to 24 and the minute from 0 to 60" << endl;
cout <<"Please input the second time:";
cin >>hour2>>a>>minute2;
if((hour2 <0 )&&( hour2 >23)||(minute2 <0)&&(minute2 >59))
cout <<"Please input the hour from 0 to 24 and the minute from 0 to 60" <<endl;
t1=60*60*hour1+60*minute1;
t2=60*60*hour2+60*minute2;
if(t1 >t2)
t=t1-t2;
else
t=t2-t1;
cout <<"The different time is: " <<t <<"S" <<endl;
return 0;
}
[解决办法]
把cout放在所有的cin后面试试
[解决办法]
因为你的输入方式用问题.冒号不能用来区分两个数字是否输入完成.回车与Tab或者空格才可以.