hey, I'm having problems with coding this program. the output is not what i wanted. any ideas?
this is the question:
The manager of the Diner by the Valley restaurant plans to have a computer available for
students to place their orders when they enter the campus centre. They have a limited menu
selection available that includes sandwiches and drinks. The manager wants the computer screen
to allow the students to select from a list of available sandwich and drink options. A large board
is located on the wall at the location where the computer will reside. It shows the menu of items
available and lists the price of each item.
In addition to white bread, they have whole wheat and rye bread. No charge is included for
different bread types; however, they do consider that selection a special request. The interface
should enable special requests such as bread types to be selected. Students should be able to
enter other special requests such as "Hold the onion" or "Hold the mayo". Water is available for
each order at no charge, but it must be ordered.
Prices are as follows:
• Sandwich = $2.00
• Tea = $1.80,
• Coffee = $2.30
• Juice = $1.50.
The manager needs a user-friendly interface where a student can choose options easily and at the
end, the program should display the current order selections and show the total cost of the order.
Requirements
Refer to the scenario given above and write codes that make extensive use of selection
statements (if-else) to create a program for Diner by the Valley restaurant.
A student should be able to make various selections using the program e.g. selections for
sandwiches and drinks, bread types, drinks, make a special request etc. The total should contain
the total value of the order the student has to pay.
Also, include a do-while loop that asks the user whether he wants to place another order. The
user response of y or Y should allow for another transaction while any other response should
terminate the program.
this is my code:
#include<iostream>
#include<cmath>
using namespace std;
cout << "Your Total Charge is : $" << total << endl << endl;
cout << "Do you want to place another Order?\n(Press 'y' for Yes or any other key to Terminate): " ;
cin >> key;
if (key = y )
cout << key << endl;
else
break;
What output are you getting - as against what is expected. What debugging of the code have you done to try to find out the issue? Where does this code differ from your tried program design?
PS. When posting code, please use code tags so that the code is readable and post formatted code.
These variables are never set to a value - so when the are displayed they have whatever value happens to be in memory at their location. The functions return a value but the return value is never used. The return value needs to be assigned to a value. eg
menu = getMenuItems();
and similar.
if (key = y )
variable y has again not been initialised - so could have any value. Also, this is an assignment not an equality test. = is assignment, == is equality test. Do you mean:
if (key == 'y')
and similar in other parts of the code.
It's good practice to always initialise a variable when it is defined.