I would really like a fresh set of eyes on my code and see what I am doing wrong. I feel like I am messing something up with my strings, as well as some other errors I probably have missed. I'd appreciate the help. I tried to put in some notes to explain what I was thinking. I'd also like to do "int cups" but changed it to "float" for ease of use.
#include <iostream>
#include <string>
usingnamespace std;
void menu();
void menu2();
float Sell_coffee(float &x, int &y, double &a); //(float cups, int ounces, double money)
void Show(int y); //(int ounces)
void Show(float x); //(float cups)
void Show(double a); //(double money)
int main()
{
cout << "Welcome to the coffee shop!\n";
menu();
}
void menu()
{
int choice, ounces = 0;
float cups = 0;
double money = 0;
cout << "\n::Please select from the following menu:\n"
<< "\n1. Buy Coffee\n"
<< "2. Show the total cups of coffee that has been sold\n"
<< "3. Show how many ounces of coffee has been sold\n"
<< "4. Show the total amount of money the coffee shop has made\n"
<< "5. Exit\n"
<< "\nEnter Choice: ";
cin >> choice;
while (choice != 5)
{
switch (choice)
{
case 1: Sell_coffee(cups, ounces);
break;
case 2: Show(cups);
break;
case 3: Show(ounces);
break;
case 4: Show(money);
break;
default: cout << "\nPlease try again\n";
}
cout << "\n::Please select from the following menu:\n"
<< "\n1. Buy Coffee\n" //Sell coffee in any size and any number of cups
<< "2. Show the total cups of coffee that has been sold\n" //Display the total number of cups sold of each size
<< "3. Show how many ounces of coffee has been sold\n" //Display the total amount of coffee sold (in ounces)
<< "4. Show the total amount of money the coffee shop has made\n" //Display the total money made
<< "5. Exit\n"
<< "\nEnter Choice: ";
cin >> choice;
}
}
void menu2()
{
int choice2, ounces;
string size;
double money;
cout << "\n::What size coffee:\n"
<< "\n1. Small\n"
<< "2. Medium\n"
<< "3. Large\n"
<< "\nEnter Choice: ";
cin >> choice2;
if (choice2 == 1)
{
size{ "Small" };
ounces = 9;
money = 1.75;
}
elseif (choice2 == 2)
{
size{ "Meduim" };
ounces = 12;
money = 1.90;
}
elseif (choice2 == 3)
{
size{ "Large" };
ounces = 15;
money = 2.00;
}
else
{
cout << "Invalid input\n";
}
}
float Sell_coffee(float &x, int &y, double &a)
{
float cups;
double money;
menu2();
cout << "How many cups would you like? \n";
cin >> cups;
money = money * cups;
return money;
return cups;
return ounces;
void Show(float x)
{
cout << "The total number of cups sold is " << x << endl;
}
void Show(int y)
{
cout << "The total number of ounces sold is " << y << endl;
}
void Show(double a)
{
cout << "The total amount of money the coffee shop has made is " << a << endl;
}
Here's your code with a few correction and comments. I only corrected it enough so that it would compile, follow my comments to make the program work correctly. Good Luck!
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
usingnamespace std;
void menu();
void menu2();
void Sell_coffee(); //(float cups, int ounces, double money) REMOVED ARGUMENTS SINCE YOU DIDN'T PROVIDE THEM IN FUNCTION CALL
void Show(int y); //(int ounces)
void Show(float x); //(float cups)
void Show(double a); //(double money)
//Don't Name 3 Functions The Same If They Don't Do The Same Thing
int main()
{
cout << "Welcome to the coffee shop!\n";
menu();
}
void menu()
{
int choice, ounces = 0; //Would make more sense for cups to be int and ounces to be a float??
float cups = 0;
double money = 0;
cout << "\n::Please select from the following menu:\n"
<< "\n1. Buy Coffee\n"
<< "2. Show the total cups of coffee that has been sold\n"
<< "3. Show how many ounces of coffee has been sold\n"
<< "4. Show the total amount of money the coffee shop has made\n"
<< "5. Exit\n"
<< "\nEnter Choice: ";
cin >> choice;
while (choice != 5) //This means if choice is equal to 5 the loop will end. You want "while(choice > 0 && choice < 5)"
{
//If choice isn't "1", Show(double a) Is ALWAYS The Function Called. CHANGE THE FUNCTION NAMES TO MATCH WHAT THE FUNCTION DOES!
switch (choice)
{
case 1: Sell_coffee(); //Trying to send 2 argument while Function was EXPECTING 3 arguments! -Removed arguments since unused
break;
case 2: Show(cups);
break;
case 3: Show(ounces);
break;
case 4: Show(money);
break;
default: cout << "\nPlease try again\n";
}
cout << "\n::Please select from the following menu:\n"
<< "\n1. Buy Coffee\n" //Sell coffee in any size and any number of cups
<< "2. Show the total cups of coffee that has been sold\n" //Display the total number of cups sold of each size
<< "3. Show how many ounces of coffee has been sold\n" //Display the total amount of coffee sold (in ounces)
<< "4. Show the total amount of money the coffee shop has made\n" //Display the total money made
<< "5. Exit\n"
<< "\nEnter Choice: ";
cin >> choice;
}
}
void menu2()
{
//All these variables are destroyed when the function call is over. Meaning Any information saved in them will be gone.
//Consider making the variables in int main() and using them as arguments or making global variables
int choice2, ounces; //Not Initialized
string size;
double money;
cout << "\n::What size coffee:\n"
<< "\n1. Small\n"
<< "2. Medium\n"
<< "3. Large\n"
<< "\nEnter Choice: ";
cin >> choice2;
if (choice2 == 1)
{
size = "Small"; //No initializer List, use an = sign
ounces = 9; //Info Will Disappear by the end of this function
money = 1.75; //Info Will Disappear by the end of this function
}
elseif (choice2 == 2)
{
size = "Meduim"; //No initializer List, use an = sign
ounces = 12; //Info Will Disappear by the end of this function
money = 1.90; //Info Will Disappear by the end of this function
}
elseif (choice2 == 3)
{
size = "Large"; //No initializer List, use an = sign
ounces = 15; //Info Will Disappear by the end of this function
money = 2.00; //Info Will Disappear by the end of this function
}
else
{
cout << "Invalid input\n";
}
}
void Sell_coffee() //Why make arguments if you wont use them? Are these Needed? Removed them So Code Would Compile
{
float cups = 0; //Was Not Initialized
double money = 0; //Was Not Initialized
//Money should be dependant on the size of the drink?
//You can send the value of "Money" from menu2 to this function through an argument
menu2();
cout << "How many cups would you like? \n";
cin >> cups;
money = money * cups;
}
//Name Them Differently As To Not Confuse Yourself and To Call The Correct Function?
void Show(float x)
{
cout << "The total number of cups sold is " << x << endl;
}
void Show(int y)
{
cout << "The total number of ounces sold is " << y << endl;
}
void Show(double a)
{
cout << "The total amount of money the coffee shop has made is " << a << endl;
}