Thread: Help in hw/proj :(

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    2

    Help in hw/proj :(

    Help i need to create a C++ program that would display the text below and will accept orders, compute for the total amount and computer for customer change after entering the given cash. The program should be looping and will end once the user answers No to the question: Another Customer (Y or N).
    that looks like this
    SBC Restaurant
    Menu
    Item No. Item Price Item No. Item Price
    1 Fries P20 7 Mineral Water P20
    2 Hamburger P25 8 Iced Tea P40
    3 Cheese Burger P30 9 Coke P35
    4 Pizza P100 10 Sprite P35
    5 Chicken (per pc) P50 11 Sago P25
    6 Spaghetti P40 12 Taho P25

    SAMPLE OUTPUT:
    Customer Name: Jane Cruz
    Enter the Order: 1
    Quantity: 2
    Additional Order(Y or N): N

    Customer Name: Jane Cruz
    Total Amount: P40.00
    Total Cash: P50.00
    Change: P10.00

    Another Customer (Y or No): Y


    Customer Name: James Yu
    Enter the Order: 12
    Quantity: 1
    Additional Order(Y or N): Y
    Enter the Order: 6
    Quantity: 1
    Additional Order(Y or N): N

    Customer Name: James Yu
    Total Amount: P65.00
    Total Cash: P100.00
    Change: P35.00

    Another Customer (Y or No): N

    i cant simply add the additional order what should i do?
    this is what i have so far
    Code:
    #include <iostream> 
    
    using namespace std;
    
    
    main()
    {
          
    char response;
    char name[50];
    int z,a,b,c,d,e,f,g,l;
    int x,y,t,s,w;
    int cash;
    
    
    
    
    cout<<"\t\tSBC Restaurant \n\n\t\t    Menu\n\n"; 
    cout<<"Item No.\tItem\t\tPrice\n";
    cout<<"1\t\tFries\t\tP20\n";
    cout<<"2\t\tHamburger\tP25\n";  
    cout<<"3\t\tCheese Burger\tP30\n";
    cout<<"4\t\tPizza\t\tP100\n";
    cout<<"5\t\tChicken\t\tP50(per pc)\n";
    cout<<"6\t\tSpaghetti\tP40\n";
    cout<<"7\t\tMineral Water\tP20\n";
    cout<<"8\t\tIced Tea\tP40\n";
    cout<<"9\t\tCoke\t\tP35\n";
    cout<<"10\t\tSprite\t\tP35\n";
    cout<<"11\t\tSago\t\tP25\n";
    cout<<"12\t\tTaho\t\tP25\n\n";    
    
    
    menu:
    cout<<"_____________________________________________________________";
    cout<<"\nCustomer name: ";
    cin>>name;
    
    
    dwin:
    cout<<"\nEnter Order: ";
    cin>>z;
    
    
    cout<<"\nQuantity: ";
    cin>>x;
         
    cout<<"\nAdditional Order (Y/N):";
    cin>>response;
    
    
    switch(response)
    {                                
    case 'y':     goto dwin;
    break;
    case 'n':
    break;
    default:;
    }
    
    
    cout<<"\n\nCustomer name: "<<name;
    
    
    a=20;
    b=25;
    c=30;
    d=100;
    e=50;
    f=40;
    g=35;
    
    
    if(z==1)
        cout<<"\nTotal Amount: P"<<a*x;
        else if(z==2)
         cout<<"\nTotal Amount: P"<<b*x;
         else if(z==3)
         cout<<"\nTotal Amount: P"<<c*x;
         else if(z==4)
         cout<<"\nTotal Amount: P"<<d*x;
         else if(z==5)
         cout<<"\nTotal Amount: P"<<e*x;
         else if(z==6)
         cout<<"\nTotal Amount: P"<<f*x;
         else if(z==7)
         cout<<"\nTotal Amount: P"<<a*x;
         else if(z==8)
         cout<<"\nTotal Amount: P"<<f*x;
         else if(z==9)
         cout<<"\nTotal Amount: P"<<g*x;
         else if(z==10)
         cout<<"\nTotal Amount: P"<<g*x;
         else if(z==11)
         cout<<"\nTotal Amount: P"<<b*x;
         else if(z==12)
         cout<<"\nTotal Amount: P"<<b*x;
         else
         goto dwin;
         
    cout<<"\nTotal Cash: P";
    cin>>cash;
    
    
    cout<<"Change: P";
    {if(z==1)
        cout<<cash-(a*x);
        else if (z==2)
         cout<<cash-(b*x);
         else if (z==3)
         cout<<cash-(c*x);
         else if (z==4)
         cout<<cash-(d*x);
         else if (z==5)
         cout<<cash-(e*x);
         else if (z==6)
         cout<<cash-(f*x);
         else if (z==7)
         cout<<cash-(a*x);
         else if (z==8)
         cout<<cash-(f*x);
         else if (z==9)
         cout<<cash-(g*x);
         else if (z==10)
         cout<<cash-(g*x);
         else if (z==11)
         cout<<cash-(b*x);
         else if (z==12)
         cout<<cash-(b*x);
         else
         goto dwin; }
    
    
    cout<<"\n\n";
    cout<<"Another Customer? (Y/N):";
    cin>>response;
    
    
    switch(response)
    {
    case 'y':goto menu;
    break;
    case 'n':
    break;
    default:;
    }
    
    
    
    
    system("pause");
    return 0;
    }
    Last edited by DDUUAANNEEE; 03-08-2013 at 05:08 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    First, read this -> SourceForge.net: Indentation - cpwiki
    Clear and consistent code layout will stop you making a lot of stupid errors (like why won't my loop work properly).

    > int z,a,b,c,d,e,f,g,l;
    > int x,y,t,s,w;
    > int cash;
    My guess is you'll wake up each morning, look at the code and have a fairly good idea what the 'cash' variable is for.
    You WILL however be completely CLUELESS as to what all those single letters are for!
    Pick meaningful variable names.

    > case 'y': goto dwin;
    This is very poor as well.
    Backward jumping gotos almost always signify that you should be using a loop.
    Code:
    do {
        cout<<"\nEnter Order: ";
        cin>>z;
     
     
        cout<<"\nQuantity: ";
        cin>>x;
           
        cout<<"\nAdditional Order (Y/N):";
        cin>>response;
    } while ( response == 'y' );
    Oh, and read this
    A development process
    Start adding some functions to break out useful blocks of code from main.
    It helps to stop your functions from becoming bloated.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    2
    Thanks salem! i will try to do it again if it dosent work ill just ask you again thanks

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    What compiler are you using? main with no return value should most definitely not compile!
    Also, get rid of the char arrays and use std::string.
    Another good advice is to declare near first use. Many of your variables don't need to be declared at the start of your function, so don't do it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    Registered User
    Join Date
    Mar 2013
    Location
    Portugal, Porto.
    Posts
    105
    As Salem said it's utterly unwise to use/name variables which are not correctly identified (int a, b, c....).
    If you used arrays you wouldn't have to define that many variables and you'd shorten your code to half of what you've got at the moment. Take a look at the code I posted on the other thread.
    Programming isn't only about finding a solution, but the BEST solution and that is something you will be aware of later on.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    The repetitive nature of portions of the code indicates that you should be using an array and a loop for those parts.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BorlandC proj
    By mary18 in forum C Programming
    Replies: 68
    Last Post: 02-20-2008, 11:22 AM
  2. export vc++ proj to dev c++
    By jay_uccs in forum C++ Programming
    Replies: 1
    Last Post: 06-26-2005, 07:43 AM
  3. Need Help on creating a Proj on Dev C++
    By djxtremor in forum C++ Programming
    Replies: 2
    Last Post: 11-19-2002, 08:24 PM
  4. Simple problem for you guys - school proj
    By ryancsutton in forum C++ Programming
    Replies: 7
    Last Post: 10-01-2002, 03:06 PM

Tags for this Thread