イントロコーディングクラスの課題を完了する際に問題が発生しました。私はこのスコープで宣言されていなかった、「[エラー] 『displayBills』のコンパイルエラーを得続ける。私は自分のコードを添付し、任意の提案をいただければ幸いです、ありがとう!スコープ内で宣言する際にエラーが発生しました
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int dollars;
cout << "Please enter the whole dollar amount (no cents!). Input 0 to terminate: ";
cin >> dollars;
while (dollars != 0)
{
displayBills(dollars);
cout << "Please enter the a whole dollar amount (no cents!). Input 0 to terminate: ";
cin >> dollars;
}
return 0;
}
displayBills(int dollars)
{
int ones;
int fives;
int tens;
int twenties;
int temp;
twenties = dollars/20;
temp = dollars % 20;
tens = temp/10;
temp = temp % 10;
fives = temp/5;
ones = temp % 5;
cout << "The dollar amount of ", dollars, " can be represented by the following monetary denominations";
cout << " Twenties: " << twenties;
cout << " Tens: " << tens;
cout << " Fives: " << fives;
cout << " Ones: " << ones;
}
定義順/前方宣言。 Btwでは、初期化されていない変数の長いリストを作成しないでください。 – LogicStuff
コンパイラがあなたのプログラムテキストを上から下に正確に1回読むとします。 displayBills()を呼び出すと、その関数の宣言や定義はまだ見られません。この問題を解決するには、displayBills()関数の定義をmain(...)関数の定義の前に置きます。 –