今週の宿題は、ユーザーに長さをフィートとインチで入力し、センチメートルで出力するよう求める基本的な C++ プログラムを作成することです。キャッチは、例外を作成し、ユーザーが負の数または文字を入力した場合にそれを処理することです。コードを作成しましたが、コンパイルするとエラーが発生します。
関数 'int main()' 内: 19 行目の "int" の前に ')' が必要です。
これが私のコードです:
#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;
}
見落としているのは簡単なことだと思いますが、自分の問題が何であるかわかりません。どんな助けでも大歓迎です。前もって感謝します。