My program got problem while calculating,
it is about ordering drink,
but each time when I want to calculate,
it will show 0 in the result,
can anyone helo me to solve the problem?
My code is as follows:
#include <iostream>
#include <cstdlib>
using namespace std;
char name [20];
long double order;
long double amount;
int counter;
char sugar;
char milk;
long double price;
int main()
{
cout<<"Enter your name:"<<endl;
cin>>name;
cout<<"Hello, "<<name<<", "<<endl;
cout<<"Welcome to drink order program"<<endl;
cout<<"Please select a drink (enter number):"<<endl;
cout<<"1. expresso"<<endl;
cout<<"2. cappucino"<<endl;
cout<<"3. latte"<<endl;
cout<<"4. Hot chocolate"<<endl;
cout<<"5. Plain Tea"<<endl;
cin>>order;
cout<<"Please enter amount:"<<endl;
cin>>amount;
cout<<"Do you wish to add sugar? (y/n)";
cin>>sugar;
cout<<"Do you wish to add milk? (y/n)";
cin>>milk;
cout<<"The total price for your order: RM"<<price<<endl;
cout<<"Thank you for ordering!"<<endl;
if (order == 1)
{
while (counter <= amount)
{
int counter = 1;
if (sugar == 'y')
{
if (milk == 'y')
{
float price = 2.50;
price = price + 1.00;
}
else if (milk == 'n')
{
float price = 2.50;
price = price + 0.50;
}
}
else if (sugar == 'n')
{
if (milk == 'y')
{
float price = 2.50;
price = price + 0.50;
}
else if (milk == 'n')
{
float price = 2.50;
price = price + 0;
}
}
counter = counter + 1;
}
return price;
}
if (order == 2)
{
while (counter <= amount)
{
int counter = 1;
float price = 2.50;
if (sugar == 'y')
{
if (milk == 'y')
{
price = price + 1.00;
}
else if (milk == 'n')
{
price = price + 0.50;
}
}
else if (sugar == 'n')
{
if (milk = 'y')
{
price = price + 0.50;
}
else if (milk == 'n')
{
price = price + 0;
}
}
counter = counter + 1;
}
return price;
}
if (order == 3)
{
while (counter <= amount)
{
int counter = 1;
float price = 2.50;
if (sugar == 'y')
{
if (milk == 'y')
{
price = price + 1.00;
}
else if (milk == 'n')
{
price = price + 0.50;
}
}
else if (sugar == 'n')
{
if (milk == 'y')
{
price = price + 0.50;
}
else if (milk == 'n')
{
price = price + 0;
}
}
counter = counter + 1;
}
return price;
}
if (order == 4)
{
while (counter <= amount)
{
int counter = 1;
float price = 2.00;
if (sugar == 'y')
{
if (milk == 'y')
{
price = price + 1.00;
}
else if (milk == 'n')
{
price = price + 0.50;
}
}
else if (sugar == 'n')
{
if (milk == 'y')
{
price = price + 0.50;
}
else if (milk == 'n')
{
price = price + 0;
}
}
counter = counter + 1;
}
return price;
}
if (order == 5)
{
while (counter <= amount)
{
int counter = 1;
float price = 1.50;
if (sugar == 'y')
{
if (milk == 'y')
{
price = price + 1.00;
}
else if (milk == 'n')
{
price = price + 0.50;
}
}
else if (sugar == 'n')
{
if (milk == 'y')
{
price = price + 0.50;
}
else if (milk == 'n')
{
price = price + 0;
}
}
counter = counter + 1;
}
return price;
}
}
then you can simply get the cost of the order like: double costOfOrder = amount * prices[order-1] + amount * costOfMilk * (milk == 'y') + amount * costOfSugar * (sugar == 'y');
And sorry for keep asking becoz im just a beginner.
Anyway, the question is as follows:
You are to create a program to manage an order. To place an order the users have to choose
among the following 5 items:
No Item RM
1 Expresso 2.50
2 Cappucino 2.50
3 Latte 2.50
4 Hot Chocolate 2.00
5 Plain Tea 1.00
The program will allow the user to enter a number between 1-5 and the quantity. The users
will also have a choice to add extra milk and extra sugar with an additional price of 50 cent
each.
Your program will output which beverage they have ordered, the quantity and the total
amount that they need to pay. Include error handling in your program should the choice
entered is outside of the range. Your program can handle any changes to be made to the order
should the users change their mind before making the payment.
please use code tags and not quote. either the <> button or put [ code] before and [/code] after (without the space). The problem is probably this line: double costorder = amount * prices + amount * 0.50 * (milk == 'y') + amount * 0.50 * (sugar == 'y'); it should be prices[order - 1] You also are not following the assignment 100% It asks for you to
Your program will output which beverage they have ordered, the quantity and the total
amount that they need to pay. Include error handling in your program should the choice
entered is outside of the range. Your program can handle any changes to be made to the order
should the users change their mind before making the payment.