![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2007
Location: Hershey, the sweetest place on earth
Posts: 19
Rep Power: 0
![]() |
Point-of-Sale
Hello! I'm kind of new to programming so please help. I have been working on a program that would present a menu so the user can choose what they wanted. Every time they chose something the program would repeatedly display the menu as the sale is being totaled. Currently, when I try to run my program it shows a never ending loop.
#include <iostream.h> // included heading
float totalsale (float s);
int main()
{
int choice;
float sale = 0.00;
do
{
cout << "What would you like to buy from the menu.\n";
cout << "S - Sandwich\n";
cout << "C - Chips\n";
cout << "B - Brownie\n";
cout << "R - Regular Drink\n";
cout << "L - Large Drink\n";
cout << "X - Cancel Sale and Start over\n";
cout << "T - Total Sale\n";
cin >> choice;
cout << "The current cost of your meal is " << sale << endl;
} while (choice != 'T');
switch(choice)
{
case 'S':
sale = sale + 2.99;
break;
case 'C':
sale = sale + 0.99;
break;
case 'B':
sale = sale + 0.99;
break;
case 'R':
sale = sale + 0.99;
break;
case 'L':
sale = sale + 1.29;
break;
case 'X':
sale = 0.00;
break;
}
float totalsale (sale);
return 0;
}
float totalsale (float function_s)
{
return function_s;
}I'm not completely finished with it. Could someone tell me what I'm doing wrong? |
|
|
|
|
|
#2 |
|
Professional Programmer
|
First try to put your switch statement inside the loop.
![]()
__________________
JG-Webdesign |
|
|
|
|
|
#3 | |
|
Hobbyist Programmer
Join Date: Nov 2006
Location: 163H
Posts: 213
Rep Power: 2
![]() |
I don`t like the int type of choice. Wouldn`t it be better being a char.
Quote:
Also the function totalsale is useless the way it is. It would be better to put all the switch statement inside the function and then output the sale statement. Good luck. ![]()
__________________
You never test the depth of a river with both feet. The believer is happy. The doubter is wise. Free speech carries with it some freedom to listen. The next generation will always surpass the previous one. It`s one of the never ending cycles of life. |
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jan 2007
Location: Hershey, the sweetest place on earth
Posts: 19
Rep Power: 0
![]() |
Okay, with a few adjustments, I got it.
#include <iostream.h> // included heading
char choice;
float sale = 0.00;
float totalsale (float s);
int main()
{
do
{
cout << "What would you like to buy from the menu.\n";
cout << "S - Sandwich\n";
cout << "C - Chips\n";
cout << "B - Brownie\n";
cout << "R - Regular Drink\n";
cout << "L - Large Drink\n";
cout << "X - Cancel Sale and Start over\n";
cout << "T - Total Sale\n";
cin >> choice;
switch(choice)
{
case 'S':
sale = sale + 2.99;
break;
case 'C':
sale = sale + 0.99;
break;
case 'B':
sale = sale + 0.99;
break;
case 'R':
sale = sale + 0.99;
break;
case 'L':
sale = sale + 1.29;
break;
case 'X':
sale = 0.00;
break;
}
cout << "The current cost of your meal is " << sale << endl;
float totalsale (sale);
} while (choice != 'T');
if (choice = 'T');
{
cout << "The final cost of your meal is " << sale << endl;
}
return 0;
}
float totalsale (float function_s)
{
return function_s;
} |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 3d Graphics. | Sane | Other Scripting Languages | 54 | Apr 7th, 2006 9:38 PM |
| Add - ins for Power Point 2003 | christophersong | Visual Basic | 0 | Dec 19th, 2005 3:32 PM |
| How to make an array of pointers-to-char point to strings | aznluvsmc | C | 38 | Sep 21st, 2005 7:45 AM |
| Finding a point on a circle | TooDice | Other Programming Languages | 15 | Jun 23rd, 2005 7:56 AM |
| various questions on class Point methods | nocturna_gr | Java | 1 | May 7th, 2005 12:45 PM |