Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 13th, 2007, 8:35 PM   #1
gamerfelipe
Newbie
 
Join Date: Jan 2007
Location: Hershey, the sweetest place on earth
Posts: 19
Rep Power: 0 gamerfelipe is on a distinguished road
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?
gamerfelipe is offline   Reply With Quote
Old Feb 13th, 2007, 8:52 PM   #2
Wizard1988
Professional Programmer
 
Wizard1988's Avatar
 
Join Date: Oct 2005
Location: Chitown
Posts: 422
Rep Power: 4 Wizard1988 is on a distinguished road
First try to put your switch statement inside the loop.
__________________

Wizard1988 is offline   Reply With Quote
Old Feb 14th, 2007, 6:32 AM   #3
pegasus001
Hobbyist Programmer
 
pegasus001's Avatar
 
Join Date: Nov 2006
Location: 163H
Posts: 215
Rep Power: 3 pegasus001 is on a distinguished road
I don`t like the int type of choice. Wouldn`t it be better being a char.

Quote:
cout << "The current cost of your meal is " << sale << endl;
Then why do you have to output sale when you have not used it at all. Better put it in the end.

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.
pegasus001 is offline   Reply With Quote
Old Feb 14th, 2007, 12:38 PM   #4
gamerfelipe
Newbie
 
Join Date: Jan 2007
Location: Hershey, the sweetest place on earth
Posts: 19
Rep Power: 0 gamerfelipe is on a distinguished road
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;
}
gamerfelipe is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
3d Graphics. Sane Other Scripting Languages 54 Apr 7th, 2006 10:38 PM
Add - ins for Power Point 2003 christophersong Visual Basic 0 Dec 19th, 2005 4:32 PM
How to make an array of pointers-to-char point to strings aznluvsmc C 38 Sep 21st, 2005 8:45 AM
Finding a point on a circle TooDice Other Programming Languages 15 Jun 23rd, 2005 8:56 AM
various questions on class Point methods nocturna_gr Java 1 May 7th, 2005 1:45 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC