【发布时间】:2021-03-12 18:15:40
【问题描述】:
我对 C++ 编程比较陌生,而且因为我的学校教学大纲在 2 年前放弃了它,所以我最近开始自学它,所以我是个菜鸟。在程序中,我正在向用户输出正确输入数据的指示,但是在运行时,编译器只显示输出并获取第一行的输入。其他两个被跳过,光标直接转到最后一行。编译器没有给我任何错误。我也尝试在每一行后面加上 endl。
double picLen, picWid, colorPrice, perimeterOfFrame, area, total, framePrice ;
char frameType, color, crown, crownAmount ;
//inputs//
cout << "Enter the length and width (in inches) of the picture : " ;
cin >> picLen, picWid ;
cout << endl ;
cout << "Enter the type of frame ('r' for regular, 'f' for fancy) : " ;
cin >> frameType ;
cout << endl ;
cout << "Choose the color (enter first letter of color name) : " ;
cin >> color ;
cout << endl ;
cout << "Do you want crowns on the sides? ('y' for yes and 'n' for no) : " ;
cin >> crown ;
cout << endl << endl ;
cout << fixed << showpoint << setprecision(2);
【问题讨论】:
-
读取一行输入后,调用
getchar(),可能是行尾字符的问题。 -
第一个问题:
cin >> picLen, picWid应该是cin >> picLen >> picWid。
标签: c++ user-input