本週的作業分配是創建一個基本的C++程序,要求用戶輸入英尺和英寸的長度,然後以釐米輸出;問題是我們要創建一個例外,並在用戶輸入負數或字符時處理它。我的代碼編寫,但是當它編譯我得到的錯誤:「int」之前的C++預期主表達式
在函數「詮釋主()」:預期基本表達式「INT」之前「INT」預期「)」之前在線路19
這裏是我的代碼:
#include <iostream>
using namespace std;
const double centimetersPerInch = 2.54; //named constant
const int inchesPerFoot = 12; //named constant
int main()
{
int feet;
int inches; //declared variables
int totalInches;
double centimeters;
//statements
cout << "Enter two integers one for feet and " << "one for inches: ";
cin >> feet >> inches;
try
{
if (int feet, int inches < 0.0)
throw "Please provide a positive number";
cout << endl;
cout << "The numbers you entered are " << feet << " for feet and " << inches << " for inches. " << endl;
totalInches = inchesPerFoot * feet + inches;
cout << "The total number of inches = " << totalInches << endl;
centimeters = centimetersPerInch * totalInches;
cout << "The number of centimeters = " << centimeters << endl;
}
catch (char* strException)
{
cerr << "Error: " << strException << endl;
}
return 0;
}
我想,這是簡單的東西,我俯瞰,但我只是無法弄清楚我的問題是什麼。任何幫助深表感謝。提前致謝。
btw,字符串文字是'const char []',而不是'char *'。 – chris 2012-08-17 04:15:38
哪一行是第19行? – 2012-09-19 19:03:44