/* Irwin Blanc mtg2 shirts.cpp */ #include <iostream> #include <string> #include
ID: 3642430 • Letter: #
Question
/*Irwin Blanc
mtg2
shirts.cpp
*/
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
enum Shirtypes{ Long,Long_x,Short,Silk,Cotton,Wool,Blue,Black,Green};
struct Shirt
{
Shirtypes types;
int sleeveType;
int material;
int size;
int price;
int color;
};
//Global constants
const string shirtypes[]={"Long","Long_x","Short","Silk","Cotton","Wool","Blue","Black","Green"};
//Function Protypes
Shirt GetShirt(Shirt);
void DisplayShirts(Shirt[],int);
void CalculateTotals(Shirt[],int,int&,int&,float&);
int main()
{
const int my_Shirts=100;
int Shirts[my_Shirts];
Shirt t1,t2,t3,t4,t5,t6,t7,t8,t9;
int option;
//Diplay menu
cout << " Database" << endl
<< " 1. Enter shirts into the database" << endl
<< " 2. Display shirts available" << endl
<< " 3. Display Report total" << endl
<< " 4. Exit" << endl
<< " Pick an option (1-4): ";
cin >> option;
// Menu-driven application
switch(option)
{
case 1: //Prompts user for data of one shirt
t1.types=Long;
t2.types=Long_x;
t3.types=Short;
t4.types=Silk;
t5.types=Cotton;
t6.types=Wool;
t7.types=Blue;
t8.types=Black;
t9.types=Green;
GetShirt(t1);
GetShirt(t2);
GetShirt(t3);
GetShirt(t4);
GetShirt(t5);
GetShirt(t6);
GetShirt(t7);
GetShirt(t8);
GetShirt(t9);
break;
case 2: // Display available shirts
break;
case 3: // Reports totals
break;
case 4:// Exit
break;
}
return 0;
}
//Shirt GetShirt(Shirt)
//Prompts user for data of one shirt
//return value:Shirt
Shirt GetShirt(Shirt& t)
{
//Prompts user for shirt
do
{
cout << " Please enter data for shirt: " << shirtypes[t.types] <<endl;
cout << " SleeveType: ";
cin >> t.sleeveType;
cout << " Material: ";
cin >> t.material;
cout << " Size: ";
cin >> t.size;
cout << " Price: ";
cin >> t.price;
cout << " Color: ";
cin >> t.color;
if(t.size<0||t.price<0)
cout << "Error... No negative numbers allowed. " << endl;
}while(t.size<0||t.price<0);
return Shirt; // error expected primary expression before ';' token. i dont understand
}
Explanation / Answer
Two errors:
method declaration Shirt GetShirt(Shirt); should be Shirt GetShirt(Shirt&);
return Shirt; should be return t;
It works fine then. The only other thing is when I run the program, I can only select a choice (input, display etc) only once, then the program terminates.
Put the switch menu in a loop and you're fine.
here's the whole code, just in case:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.