我试图让程序在没有它的情况下正确退出。我有'|' 作为我的出口,如果它是我第一次运行时做的第一件事,它会很好地关闭。但是在输入值并打印它们之后,然后输入'|' 退出。它打印出:“较小的值是 0 较大的是前第二个值”//想要从显示中删除它
int main()
{
double first = 0, second = 0;
while(cin.good()){
char exit;
cout << "Enter '|' to exit.\n";
cout << "Enter two numbers:";
cin >> first >> second;
exit = cin.peek();
if(exit=='|'){
break;}
else{
if(first<second){
cout << "\nThe smaller value is " << first << "\nThe larger value is " << second << endl;
}
else if(first>second){
cout << "\nThe smaller value is " << second << "\nThe larger value is " << first << endl;
}
}
}
}