新手在這裏,我的結構化數組參數被髮送到函數有一些困難。看來我的基本流血編譯器不喜歡我設置的功能。我已經對整個項目做了一些改進,但幾個小時一直在努力。我試着在這個網站上查看類似的程序,但沒有足夠類似的針對這些錯誤。我的庫存功能的工作是發送一條消息,說可口可樂= 0時飲料已售罄。任何幫助將不勝感激。我已經將int main後的函數定義從底部移到頂部以清除不同的編譯器錯誤。我接受這個程序任何部分的所有反饋,因爲它是一個類的任務,可以使用指針在我的下一個測試中取得成功。 謝謝結構,數組,函數
#include<iostream>
#include<iomanip>
using namespace std;
struct Soda
{
string name;
float price;
int inv;
};
void functInventory(Soda[],int); //prototype
void functInventory(Soda drink[],int num) //function definition
{
if (drink[num].inv = 0)
cout << "SOLD OUT" <<endl;
}
int main()
{
const int option = 5;
string cola, rbeer, lemlime, grape, cream;
int InsAmount, choice;
int income = 0;
Soda array[option] = {
{cola, .75, 20},
{rbeer, .75, 20},
{lemlime,.75, 20},
{grape, .80, 20},
{cream, .80, 20}
};
cout << "Please choose 1-6 " << endl;
cout << " 1. Cola = $.75 " << endl;
cout << " 2. Root Beer = $.75 " << endl;
cout << " 3. Lemon Lime = $.75 " << endl;
cout << " 4. Grape Soda = $.80 " << endl;
cout << " 5. Cream Soda = $.80 " << endl;
cout << " 6. QUIT & EXIT " << endl;
switch(choice)
{
case 1: array[0].inv - 1 = array[0].inv;
income = income + .75;
functInventory(array, choice);
break;
case 2: array[1].inv - 1 = array[1].inv;
income = income + .75;
functInventory(array, choice);
break;
case 3: array[2].inv - 1 = array[2].inv;
income = income + .75;
functInventory(array, choice);
break;
case 4: array[3].inv - 1 = array[3].inv;
income = income + .80;
functInventory(array, choice);
break;
case 5: array[4].inv - 1 = array[4].inv;
functInventory(array, choice)
income = income + .80;
break;
case 6: cout << "The total amount earned is: $" << income <<endl;
break;
default:
cout << "Please enter a capital letter from 1-6 " << endl;
}
cout << "Please Tell Me How Much Money You Are Inserting: " <<endl;
cin >> InsAmount;
change = InsAmount - .75; //I will work on creating a more accurate function 4 change
cout << "your change is " << change; << " "<< endl;
return 0;
}
「我基本的流血編譯器不喜歡我設置的功能」是什麼意思? –
Bloodshed C++是使用的IDE。這是一個默認使用MinGW的Windows IDE。代碼中有一些語法錯誤。 – austin
我的意思是它給了我錯誤。對不起 – delgadough