The repetition structure: the while statement not working


Posted on 16th Feb 2014 07:03 pm by admin

New programming student, have assignment as follows:
A restaurant has 4 lunch combos for customers to choose:

Combo A : Fried chicken with slaw [price: 4.25]
Combo B : roast beef with mashed potato [price: 5.75]
Combo C : Fish and chips [price:5.25]
Combo D : soup and salad [price: 3.75]

Write a program to calculate how much a party of customers should pay. Suppose the party orders 2 B’s, 1 A and 3 D’s. The casher will enter B, B, A, D, D, D and T into the program. The T means “calculating total of the order”. It is a signal telling the computer that the whole order has been entered and it is time to calculate the total amount the party should pay. Assume there is no sales tax. The following is an example:

Enter item ordered [A/B/C/D] or T to calculate total: B
Enter item ordered [A/B/C/D] or T to calculate total: B
Enter item ordered [A/B/C/D] or T to calculate total: A
Enter item ordered [A/B/C/D] or T to calculate total: D
Enter item ordered [A/B/C/D] or T to calculate total: D
Enter item ordered [A/B/C/D] or T to calculate total: D
Enter item ordered [A/B/C/D] or T to calculate total: T
Please pay this amount: 27

Have tried this example and something longer also. Cannot get the program to give any output after entering initial "combo" choice {A/B/C/D/T]. Must use "while" in this assignment. Book is no help, niether is my friend. What am I missing? below is my code so far:

// Lab08P3.cpp - Calculate and display how much a party of
// restaurant customers should pay for different combos.
// Created on 10/18/09

#include

using std::cout;
using std::cin;
using std::endl;

int main( )
{
double cost = 0.0;
double costa = 0.0;
double costb = 0.0;
double costc = 0.0;
double costd = 0.0;
double costt = 0.0;
char answer = ' ';
char wouldorder = ' ';


cout <<"Would you like to order? ";
cin >>wouldorder;
wouldorder =toupper (wouldorder);


cout <<"Please enter your choice of combo's letter [A/B/C/D] from the list below:" < cout << " Combo A : Fried chicken with slaw [price: 4.25]" << endl;
cout << " Combo B : Roast beef with mashed potato [price: 5.75]" << endl;
cout << " Combo C : Fish and chips [price:5.25]" << endl;
cout << " Combo D : Soup and salad [price: 3.75]" << endl< while (wouldorder == 'Y')
{
cout << " Enter item ordered [A/B/C/D] or T to calculate total: ";
cin >> answer;
answer = toupper(answer);

while (answer == 'A')
{costa = 4.75;}
while (answer == 'B')
{costb = 5.75;}
while (answer == 'C')
{costc = 5.25;}
while (answer == 'D')
{costd = 5.75;}


while (answer == 'T')
{ costt = costa + costb + costc + costd;
cout <<"Your Total bill comes to: " << costt < }
}
system("pause");
return 0;
}
Thanks in advance for the help

No comments posted yet

Your Answer:

Login to answer
328 Like 5 Dislike
Previous forums Next forums
Other forums

New to mysqli library - Multiple query problem
Greetings,

I am writing a batch program that executes 3 queries on a single page. Using mysql

Setting/Modify Headers using mail() function
I have a question about setting email headers when using mail() in a php script.

When I send

disabling a button server-side then re-enabling client-side breaks button postback
I have a tabbed container and a button (not in the container) on a page. If the first tab is selecte

Good Programming and Web Design Books
Hi,

I recived a pm today from a fellow phpfreaker regarding php books, i replied with the fo

Creating a db with a query
Hello everyone.
I'm having troubles creating a db with a query.
I'm reading a book called PHP

Sessions work for me and not others?
I'm having a bit of bad luck with sessions. In the past they have worked fine for me, but this time

gmdate() - want 1 hr before time
Hi,
I am using php gmdate().
Now I am entering all dates in my dbase using gmdate("Y-m-d

list files from folder, only one for each date
I have many files in a folder and wish to only list one of each date

these are the file names

Using system() and bringing back the results
I am aware that you can use system() within PHP to execute system commands, but I was wondering if t

ereg_replace()
Basically what i need to do is

$title = "This Suck's"

$striped = ereg_repl

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash