0
guys sorry about my post earlier . this is what i did with my program but i dont think my equation is correct because whenever i want to get
the total amount due it always give the wrong amount . i dont thinks this equation is correct "amount=amount+price*quant;"
guys i need your help. Thank you!




#include<iostream>
#include <windows.h>

using namespace std;

      void gotoxy(long x, long y) 
      {
           COORD pos = {x, y};
           SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
      }

main()
{
      char name [25];
      int order;
      int quant=0;
      int amount=0;
      double cash;
      double change;
      char again;
      char another;
      int a, x;
      int cq=0;

      do
      {
        cout<<"\t\t\tTAPSI NI VIVIAN'S MENU";
           gotoxy(1,2);
             for(x=1; x<=6; x++)
             {
                cout<<"\n"<<x<<".";
                cout<<"\n";
             }
           gotoxy(3,3);
           cout<<"Tapsilog=P80.00" <<"\t\t\t" <<"7. Beef Mami=P50.00";
               gotoxy(0,4);
               for(a=0; a<=70; a++)
               {
                 cout<<"-";
               }
           gotoxy(3,5);
           cout<<"Tosilog=P80.00" <<"\t\t\t" <<"8. Bottled Softdrinks=P25.00";
               gotoxy(0,6);
               for(a=0; a<=70; a++)
               {
                 cout<<"-";
               }
           gotoxy(3,7);
           cout<<"Longsilog=P95.00" <<"\t\t\t" <<"9. Canned Softdrink=P25.00";
               gotoxy(0,8);
               for(a=0; a<=70; a++)
               {
                 cout<<"-";
               }
           gotoxy(3,9);
           cout<<"Bulalo=P225.00"<<"\t\t\t" <<"10. Minute Maid=P30.00";
               gotoxy(0,10);
               for(a=0; a<=70; a++)
               {
                 cout<<"-";
               }
           gotoxy(3,11);
           cout<<"Sisig with Egg=P140.00"<<"\t\t"<<"11. Nestea=P20.00";
               gotoxy(0,12);
               for(a=0; a<=70; a++)
               {
                 cout<<"-";
               }
           gotoxy(3,13);
           cout<<"Goto=P40.00"<<"\t\t\t\t"<<"12. Bottled watter=P15.00";
           gotoxy(0,15);


         cout<<"\nCustomer name: ";
         gets(name);

          do
          {
            cout<<"\nHello there "<<name<<", welcome to Tapsi Ni Vivian! What is your order? ";
            cin>>order;

            cout<<"How many orders will that be?: ";
            cin>>quant;

            if (order==1)
         {
            amount=amount+80*quant;
         }

         else if (order==2)
         {
            amount=amount+80*quant;
         }

         else if (order==3)
         {
            amount=amount+95*quant;
         }

         else if (order==4)
         {
            amount=amount+225*quant;
         }

         else if (order==5)
         {
            amount=amount+140*quant;
         }

         else if (order==6)
         {
            amount=amount+40*quant;
         }

         else if (order==7)
         {
            amount=amount+50*quant;
            cq=quant;
         }

         else if (order==8)
         {
            amount=amount+25*quant;
            cq=quant;
         }

         else if (order==9)
         {
            amount=amount+25*quant;
            cq=quant;
         }

         else if (order==10)
         {
            amount=amount+30*quant;
            cq=quant;
         }

         else if (order==11)
         {
            amount=amount+20*quant;
            cq=quant;
         }

         else if (order==12)
         {
            amount=amount+15*quant;
            cq=quant;
         }

         else;

            cout<<"Want to add an another order? (Y or N): ";
            cin>>again;
            cout<<"\n";

          }while (again=='y'||again=='Y');

         cout<<"Customer name: "<<name;

         cout<<"\nYour total amount is P"<<amount;

         cout<<"\nTotal cash: P";
         cin>>cash;

         change=cash-amount;
         cout<<"Your change will be P"<<change;

         cout<<"\n\nThank you for ordering "<<name<<", please come again soon! :)";

         cout<<"\n\nAre there any more customers? (Y or N): ";
         cin>>another;
         cout<<"\n\n";

         if (another=='y'||another=='Y')
         system("cls");
         else
         cout<<"***end of program***";

         cin.ignore();

      }while(another=='y'||another=='Y');

      cout<<"\n\n";
      system ("pause");
      return 0;
}
2
Contributors
1
Reply
33
Views
3 Years
Discussion Span
Last Post by David W
1

Using several functions ... a function for each task ...

could really help your program development ...

and help elucidate the logic flow.

// restaurant.cpp //


#include <iostream>
#include <string>

// to keep code portable ... best not to use this //
#include <windows.h> 


using namespace std;


const string HEADER = "TAPSI NI VIVIAN'S MENU";

struct Item
{
    string name;
    double price;
} ;

// putting data here, in an array of struct ... 
// makes your program more generic
// i.e. easier to revise ...
const Item MENU[] =
{
    { "Tapsilog", 80.00 }, { "Longsilog", 95.00 },
    { "Bulalo", 225.00 }, { "Sisig with Egg", 140.00 },
    { "Beef Mami", 50.00 }, { "Bottled Softdrinks", 25.00 },
    { "Canned Softdrink", 25.00 }, { "Minute Maid", 30.00 },
    { "Nestea", 20.00 }, { "Bottled watter", 15.00 }
} ;

const int NUM_CHOICES = sizeof MENU / sizeof *MENU;

// to keep code portable ... best not to use this //
void gotoxy(short x, short y)
{
    COORD pos = {x, y};
    SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}

void printMsgAt( const Item& itm, short x, short y )
{
    gotoxy( x, y );
    cout << itm.name << " P" << itm.price;
}

double getOrder( string& name )
{
    string msg, line( 65, '-' ); // construct string 65 '-'

    double amount = 0;
    for( ; ; ) // loop forvever until ... break or return ...
    {
        gotoxy( (60-HEADER.size())/2, 0 );
        cout << HEADER;

        short i;
        for( i = 0; i < NUM_CHOICES; i += 2 )
        {
            gotoxy(0, 3+i );
            cout << i+1 << '.';
            printMsgAt( MENU[i], 3, 3+i );
            gotoxy(40, 3+i );
            cout << i+2 << '.';
            printMsgAt( MENU[i+1], 43, 3+i  );
            gotoxy( 0, 4+i );
            cout << line;
        }

        gotoxy(0,i+3 );
        cout<<"\nCustomer name: ";
        getline( cin, name );

        cout <<"\nHello there "<<name
             <<", welcome to Tapsi Ni Vivian! \n";


        int quant = 0, orderNum = 0;
        char reply;

        for( ; ; )
        {
            gotoxy(0,i+8 );
            cout << "Enter # 1.." << NUM_CHOICES <<": ";

            if( cin>>orderNum && cin.get() == '\n' &&
                 orderNum > 0 && orderNum <= NUM_CHOICES )
            {
                cout<<"Enter number of #" << orderNum << " desired: ";
                if( cin>>quant && cin.get() == '\n' )
                {
                    // accept ...
                }
            }
            else
            {
                cin.clear();
                cin.sync();
                cout << "\nInvalid entry ... try again.\n";
                cout << "\nPress 'Enter' to continue ... ";

                gotoxy( 0, i+8 );
                cout << string( 479, ' ' );
                continue;
            }

            cout<<"Add to order (Y or N): ";
            cin>>reply;
            cin.ignore();

            cout<<"\n";
            if( reply == 'y' || reply == 'Y' )
            {
                amount += quant * MENU[quant-1].price;
            }
            else cout << "Not added ... \n";

            cout << "More (Y or N): ";
            cin>>reply;
            cin.ignore();

            if( !(reply == 'y' || reply == 'Y' ) )
                return amount;

            gotoxy( 0, i+8 );
            cout << string( 479, ' ' );
        }
    }
    return amount;
}


int main()
{
    // your code goes here ...
}

Edited by David W: added comments

Votes + Comments
excellent advice
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.