新手在这里,我的结构化数组参数被发送到函数中遇到了一些困难。看来我的基本流血编译器不喜欢我设置的功能。我对整个程序进行了一些改进,但已经为此苦苦挣扎了好几个小时。我尝试查看该站点上的类似程序,但没有足够相似的程序让我指出错误。我的库存功能的工作是在可乐 = 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;
}