Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   C++ (http://www.programmingforums.org/forum15.html)
-   -   Point-of-Sale (http://www.programmingforums.org/showthread.php?t=12569)

gamerfelipe Feb 13th, 2007 8:35 PM

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?

Wizard1988 Feb 13th, 2007 8:52 PM

First try to put your switch statement inside the loop.:)

pegasus001 Feb 14th, 2007 6:32 AM

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.:)

gamerfelipe Feb 14th, 2007 12:38 PM

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;
}



All times are GMT -5. The time now is 1:50 AM.

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