Can somebody check my program code? Unable to compile. C++ #include <iostream> #
ID: 3562605 • Letter: C
Question
Can somebody check my program code? Unable to compile. C++
#include <iostream>
#include <iomanip>
using namespace std;
void BuyCoffee1(char&, double, double, double);
void instructionrerun();
void BuyCoffee(int type, int amount);
void ShowCoffeeSold();
void ShowProfit();
int main ()
{
//char size;
//double smallCoffee = 1.75;
//double mediumCoffee = 1.90;
//double largeCoffee = 2.00;
//double profit;
cout<<"Welcome to JASONS's Coffee Shop" << endl;
cout <<"What size of coffee do you want"<< endl;
cout <<"Small: Medium : Large:" << endl;
cout <<"Price for Cup: S - 1.75: M - 1.90: L - 2.00:" <<endl;
cout << "Show profit and total of Coffee sold" <<endl;
ShowProfit();
return 0;
}
void instructionrerun()
{
cout<<"Instructions"<< endl;
cout <<"Select Coffee Cup Size"<< endl;
cout <<"How Many Cups do you want today"<< endl;
cout<< " cup of coffee"<< endl;
}
void BuyCoffee1(char&size, double smallCoffee, double mediumCoffee, double largeCoffee)
{
//double smallPrice = 1.75;
//double mediumPrice = 1.90;
//double largePrice = 2.00;
//int smallsSold = 0;
//int mediumsSold = 0;
//int largesSold = 0;
//double amount;
//charagain, fixed, character;
cout <<"Cup Size ";
cout <<"Small Cup " << smallCoffee<< endl;
cout <<"Medium Cup " << mediumCoffee<< endl;
cout <<"Large Cup " << largeCoffee<< endl;
cout <<"A for Buy Coffee"<< endl;
cout <<"B for Buy Coffee"<< endl;
cout <<"C for Buy Coffee"<< endl;
cout <<"X to skip"<< endl;
cout <<"Enter your choice"<<endl;
//character=getchar();
switch(character)
{
int type, amount;
case'A':
BuyCoffee(type, amount);
break;
case 'B':
ShowCoffeeSold();
break;
case 'C':
ShowProfit();
break;
default:
cout <<"no choice"<<endl;
}
}
void BuyCoffee(int type, int amount)
{
double smallPrice = 1.75;
double mediumPrice = 1.90;
double largePrice = 2.00;
int smallsSold = 0;
int mediumsSold = 0;
int largesSold = 0;
double profit;
cout << "Do you like small coffee, medium coffee or large coffee?";
cout <<" 1 for small"<< endl;
cout <<" 2 for medium"<< endl;
cout <<" 3 for large"<< endl;
cout <<" 4 for skip"<< endl;
cout <<"Enter you choice";
cin>> type;
switch(type)
{
case 1:
cout <<" The size small"<< endl;
cout <<" how many?";
cin>> amount;
profit += smallPrice * amount;
smallsSold+= amount;
cout << amount << "small coffee for $ " << smallPrice * amount;
break;
case 2:
cout <<" The size medium"<< endl;
cout <<" how many?";
cin>> amount;
profit += mediumPrice * amount;
mediumsSold+= amount;
cout << amount << "medium coffee for $ " << smallPrice * amount;
break;
case 3:
cout <<" The size large"<< endl;
cout <<" how many?";
cin>> amount;
profit += largePrice * amount;
largesSold+= amount;
cout << amount << "large coffee for $ " << smallPrice * amount;
break;
default:
cout<<"no choice";
}
char again;
if(amount<=0)
cout<<endl<<"thank you for your busines";
else
cout<<endl<<"Would you like to order something else (y/n)?";
cin>> again;
if(again=='y'|| again=='y')
{
cout<<"select"<<endl;
BuyCoffee(type, amount);
}
if(amount<=0)
cout <<endl<<"thanks for your order!";
else
cout<<endl<<"Would you like to order something else (y/n)?";
cin>> again;
if(again=='y'|| again=='y')
{
cout<<"select"<<endl;
BuyCoffee(type, amount);
}
else
if(again=='n'|| again=='n')
{
cout <<"thanks and good bye!";
}
}
void ShowCoffeeSold()
{
double smallsSold, largesSold, mediumsSold;
cout<<"coffee sold";
cout<<"Type Amount";
cout<<"Small "<<smallsSold<<" ";
cout<<"Medium "<<mediumsSold<<" ";
cout<<"Small "<<largesSold<<" ";
cout <<"Total "<<smallsSold+ mediumsSold + largesSold<<"";
}
void ShowProfit()
{
double smallPrice, smallsSold, mediumPrice, largePrice, largesSold, mediumsSold;
cout<<"Profit";
cout<<"Profit for small:"<<smallsSold* smallPrice<<" ";
cout<<"Profit for medium:"<<mediumsSold* mediumPrice<<" ";
cout<<"Profit for large:"<<largesSold* largePrice<<" ";
cout<<"Total Profit:"<<(smallsSold * smallPrice)+(mediumsSold * mediumPrice)+(largesSold * largePrice);
}
Explanation / Answer
Error : variable 'character' was not declared
#include <iostream>
#include <iomanip>
using namespace std;
void BuyCoffee1(char&, double, double, double);
void instructionrerun();
void BuyCoffee(int type, int amount);
void ShowCoffeeSold();
void ShowProfit();
int main ()
{
//char size;
//double smallCoffee = 1.75;
//double mediumCoffee = 1.90;
//double largeCoffee = 2.00;
//double profit;
cout<<"Welcome to JASONS's Coffee Shop" << endl;
cout <<"What size of coffee do you want"<< endl;
cout <<"Small: Medium : Large:" << endl;
cout <<"Price for Cup: S - 1.75: M - 1.90: L - 2.00:" <<endl;
cout << "Show profit and total of Coffee sold" <<endl;
ShowProfit();
return 0;
}
void instructionrerun()
{
cout<<"Instructions"<< endl;
cout <<"Select Coffee Cup Size"<< endl;
cout <<"How Many Cups do you want today"<< endl;
cout<< " cup of coffee"<< endl;
}
void BuyCoffee1(char&size, double smallCoffee, double mediumCoffee, double largeCoffee)
{
//double smallPrice = 1.75;
//double mediumPrice = 1.90;
//double largePrice = 2.00;
//int smallsSold = 0;
//int mediumsSold = 0;
//int largesSold = 0;
//double amount;
//charagain, fixed, character;
cout <<"Cup Size ";
cout <<"Small Cup " << smallCoffee<< endl;
cout <<"Medium Cup " << mediumCoffee<< endl;
cout <<"Large Cup " << largeCoffee<< endl;
cout <<"A for Buy Coffee"<< endl;
cout <<"B for Buy Coffee"<< endl;
cout <<"C for Buy Coffee"<< endl;
cout <<"X to skip"<< endl;
cout <<"Enter your choice"<<endl;
char character;
cin>>character;
switch(character)
{
int type, amount;
case'A':
BuyCoffee(type, amount);
break;
case 'B':
ShowCoffeeSold();
break;
case 'C':
ShowProfit();
break;
default:
cout <<"no choice"<<endl;
}
}
void BuyCoffee(int type, int amount)
{
double smallPrice = 1.75;
double mediumPrice = 1.90;
double largePrice = 2.00;
int smallsSold = 0;
int mediumsSold = 0;
int largesSold = 0;
double profit;
cout << "Do you like small coffee, medium coffee or large coffee?";
cout <<" 1 for small"<< endl;
cout <<" 2 for medium"<< endl;
cout <<" 3 for large"<< endl;
cout <<" 4 for skip"<< endl;
cout <<"Enter you choice";
cin>> type;
switch(type)
{
case 1:
cout <<" The size small"<< endl;
cout <<" how many?";
cin>> amount;
profit += smallPrice * amount;
smallsSold+= amount;
cout << amount << "small coffee for $ " << smallPrice * amount;
break;
case 2:
cout <<" The size medium"<< endl;
cout <<" how many?";
cin>> amount;
profit += mediumPrice * amount;
mediumsSold+= amount;
cout << amount << "medium coffee for $ " << smallPrice * amount;
break;
case 3:
cout <<" The size large"<< endl;
cout <<" how many?";
cin>> amount;
profit += largePrice * amount;
largesSold+= amount;
cout << amount << "large coffee for $ " << smallPrice * amount;
break;
default:
cout<<"no choice";
}
char again;
if(amount<=0)
cout<<endl<<"thank you for your busines";
else
cout<<endl<<"Would you like to order something else (y/n)?";
cin>> again;
if(again=='y'|| again=='y')
{
cout<<"select"<<endl;
BuyCoffee(type, amount);
}
if(amount<=0)
cout <<endl<<"thanks for your order!";
else
cout<<endl<<"Would you like to order something else (y/n)?";
cin>> again;
if(again=='y'|| again=='y')
{
cout<<"select"<<endl;
BuyCoffee(type, amount);
}
else
if(again=='n'|| again=='n')
{
cout <<"thanks and good bye!";
}
}
void ShowCoffeeSold()
{
double smallsSold, largesSold, mediumsSold;
cout<<"coffee sold";
cout<<"Type Amount";
cout<<"Small "<<smallsSold<<" ";
cout<<"Medium "<<mediumsSold<<" ";
cout<<"Small "<<largesSold<<" ";
cout <<"Total "<<smallsSold+ mediumsSold + largesSold<<"";
}
void ShowProfit()
{
double smallPrice, smallsSold, mediumPrice, largePrice, largesSold, mediumsSold;
cout<<"Profit";
cout<<"Profit for small:"<<smallsSold* smallPrice<<" ";
cout<<"Profit for medium:"<<mediumsSold* mediumPrice<<" ";
cout<<"Profit for large:"<<largesSold* largePrice<<" ";
cout<<"Total Profit:"<<(smallsSold * smallPrice)+(mediumsSold * mediumPrice)+(largesSold * largePrice);
}