我正在完成一項實驗室任務,其中提示用戶輸入他們希望訂購的魚的類型並輸入每磅價格。在報告打印之前,需要提示用戶輸入魚類的類型和價格兩次。第一次嘗試期間循環失敗
問題是程序在循環的第一個實例完成之前結束。 (編寫代碼的方式報告中的標題將打印兩次,但是在說明中。)
代碼如下,非常感謝您的幫助。
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
float price;
string fishType;
int counter = 0;
// Change the console's background color.
system ("color F0");
while (counter < 3){
// Collect input from the user.
cout << "Enter the type of seafood: ";
cin >> fishType; // <------ FAILS AT THIS POINT. I GET THE PROMPT AND AT THE "ENTER" IT DISPLAYS THE REPORT
cout << "Enter the price per pound using dollars and cents: ";
cin >> price;
counter++;
}
// Display the report.
cout << " SEAFOOD REPORT\n\n";
cout << "TYPE OF PRICE PER" << endl;
cout << "SEAFOOD POUND" << endl;
cout << "-------------------------------" << endl;
cout << fixed << setprecision(2) << showpoint<< left << setw(25)
<< fishType << "$" << setw(5) << right << price << endl;
cout << "\n\n";
system ("pause");
return 0;
}
你能告訴它的確切位置結束?在結束之前是否收到提示? – 2013-02-20 23:12:54
TIme運行調試器,看看哪一行失敗... – 2013-02-20 23:13:13