Assignment C++ (Example 1)


Assignment C++

Write a program that asks user to enter the type of cakes and the quantity. Based on the selection, display the user’s choice and calculate the total price. If the choice is not in the list, display error message. If the user choose to exit from the system, put exit(0); statement and put #include <stdlib.h>. The program should allow users to make more than one choice. You are required to provide the output for each choice as the given sample output:
Sample output

Solution : 

#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
 char choice='Y';
 int cake,quantity,total;

 while(choice=='Y')
 {
  cout << "\n         Eve n Soul Cakes House            "<<endl;
  cout << "###########################################"<<endl;
  cout << "1. Chocolate Moist Cake (1 kg)- RM45       "<<endl;
  cout << "2. Blueberry Cheese Cake (1 kg)- RM40      "<<endl;
  cout << "3. Cupcakes (25 pieces) - RM50             "<<endl;
  cout << "4. Exit                                    "<<endl;

  cout << "Please enter your choice:";
  cin >> cake;

if(cake == 1)
{
cout << "You select Chocolate Moist Cake";
cout << "\nPlease enter quantity : ";
cin >> quantity;
total = quantity * 45;
cout << "The total price is : RM"<<total;

cout << "\n\nDo you want to continue with other options? (Y/N):";
cin >> choice;
}
else
if (cake == 2)
{
cout << "You select Blueberry Cheese Cake";
cout << "\nPlease enter quantity : ";
cin >> quantity;
total = quantity * 40;
cout << "The total price is : RM"<<total;

cout << "\n\nDo you want to continue with other options? (Y/N):";
cin >> choice;
}
else
if (cake == 3)
{
cout << "You select Cupcakes";
cout << "\nPlease enter quantity : ";
cin >> quantity;
total = quantity * 50;
cout << "The total price is : RM"<<total;

cout << "\n\nDo you want to continue with other options? (Y/N):";
cin >> choice;
}
else
if(cake == 4)
exit(0);



 }
 exit(0);
 return 0;
}

Share this

Related Posts

Previous
Next Post »