Thread: Need help!!

  1. #1
    Registered User
    Join Date
    Jan 2018
    Posts
    2

    Need help!!

    So I was preparing a program on DOSBOX for school EXAM but there is a problem and i wasn't able to identify it. BILL is not giving desired outout. Here is code-
    Code:
    #include<iostream.h>
    #include<conio.h>
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<dos.h>
    int n,c,c1,c2,c3,c4,c5,q,q1,q2,q3,q4,q5,l,l1,l2,l3,l4,l5;
    char nm[15],pr[25],pr1[25],pr2[25],pr3[25],pr4[25],pr5[25];
    void menu();
    void bill();
    void main()
    {clrscr();
     cout<<"--------------------------------------------------------------------------------";
     cout<<"                           WELCOME TO CYGNETT INN"<<endl;
     cout<<"--------------------------------------------------------------------------------";
     cout<<"Please enter your name "<<endl;
     gets(nm);
     cout<<"Please enter number of people with you "<<endl;
     cin>>n;
     randomize();
     cout<<"Please go to table number "<<random(10)<<" and wait for waiter to attend you"<<endl;
     menu();
     bill();
     getch();
    }
    void menu()
    {int o,p;
     delay(2000);cout<<"Hello sir,Here is your menu"<<endl;
     delay(1000);
     for(int i=0;i<5;i++)
     {cout<<"--------------------------------------------------------------------------------";
      cout<<"|                             CYGNETT INN'S Menu                               |";
      cout<<"--------------------------------------------------------------------------------";
      cout<<"| S.No.           Name           Price | S.No.           Name           Price  |";
      cout<<"|               CHINESE                |                PASTA                  |";
      cout<<"| 01       Veggie Fry Rice        95   | 16       Arrabbiate Pasta       95    |";
      cout<<"| 02       Veggie Paneer Rice     110  | 17       Cheese Pasta           105   |";
      cout<<"| 03       Schezwan Fry Rice      100  | 18       Cream Tomato Pasts     110   |";
      cout<<"| 04       Veg Manchurian         90   |            SIDE ORDERS                |";
      cout<<"| 05       Paneer Manchurian      120  | 19       French Fries           35    |";
      cout<<"| 06       Paneer Noodles         95   | 20       Sweet Corn             40    |";
      cout<<"| 07       Mushroom Noodles       80   | 21       Veggie Roll            70    |";
      cout<<"| 08       Veggie Momos           60   | 22       Paneer Roll            95    |";
      cout<<"| 09       Fried Momos            55   |              DRINKS                   |";
      cout<<"| 10       Potato Chilli          90   | 23       Cold Coffee            55    |";
      cout<<"| 11       Mushroom Chilli        125  | 24       Orange Smothie         60    |";
      cout<<"|               BURGERS                | 25       Choclate Smothie       65    |";
      cout<<"| 12       Aloo Patty Burger      50   |                                       |";
      cout<<"| 13       Veggie Burger          45   |                                       |";
      cout<<"| 14       Aloo Cheese Burger     55   |                                       |";
      cout<<"| 15       Veggie Cheese Burger   60   |                                       |";
      cout<<"--------------------------------------------------------------------------------";
      cout<<"Enter number to order the product ";
      cin>>p;
      switch(p)
      {case 1:{strcpy(pr , "Veggie Fry Rice");
           c=95;
           l=strlen(pr);
           break;
          }
       case 2:{strcpy(pr , "Veggie Paneer Rice");
           c=110;
           l=strlen(pr);
           break;
          }
       case 3:{strcpy(pr , "Schezwan Fry Rice");
           c=100;
           l=strlen(pr);
           break;
          }
       case 4:{strcpy(pr , "Veg Manchurian");
           c=90;
           l=strlen(pr);
           break;
          }
       case 5:{strcpy(pr , "Paneer Manchurian");
           c=120;
           l=strlen(pr);
           break;
          }
       case 6:{strcpy(pr , "Paneer Noodles");
           c=95;
           l=strlen(pr);
           break;
          }
       case 7:{strcpy(pr , "Mushroom Noodles");
           c=80;
           l=strlen(pr);
           break;
          }
       case 8:{strcpy(pr , "Veggie Momos");
           c=60;
           l=strlen(pr);
           break;
          }
       case 9:{strcpy(pr , "Fried Momos");
           c=55;
           l=strlen(pr);
           break;
          }
       case 10:{strcpy(pr , "Potato Chilli");
            c=90;
            l=strlen(pr);
            break;
           }
       case 11:{strcpy(pr , "Mushroom Chilli");
            c=125;
            l=strlen(pr);
            break;
           }
       case 12:{strcpy(pr , "Aloo Patty Burger");
            c=50;
            l=strlen(pr);
            break;
           }
       case 13:{strcpy(pr , "Vegie Burger");
            c=45;
            l=strlen(pr);
            break;
           }
       case 14:{strcpy(pr , "Aloo Cheese Burger");
            c=55;
            l=strlen(pr);
            break;
           }
       case 15:{strcpy(pr , "Vegie Cheese Burger");
            c=60;
            l=strlen(pr);
            break;
           }
       case 16:{strcpy(pr , "Arrabbiate Pasta");
            c=95;
            l=strlen(pr);
            break;
           }
       case 17:{strcpy(pr , "Cheese Pasta");
            c=105;
            l=strlen(pr);
            break;
           }
       case 18:{strcpy(pr , "Cream Tomato Pasta");
            c=110;
            l=strlen(pr);
            break;
           }
       case 19:{strcpy(pr , "French Fries");
            c=35;
            l=strlen(pr);
            break;
           }
       case 20:{strcpy(pr , "Sweet Corn");
            c=40;
            l=strlen(pr);
            break;
           }
       case 21:{strcpy(pr , "Veggie Roll");
            c=70;
            l=strlen(pr);
            break;
           }
       case 22:{strcpy(pr , "Paneer Roll");
            c=95;
            l=strlen(pr);
            break;
           }
       case 23:{strcpy(pr , "Cold Coffee");
            c=55;
            l=strlen(pr);
            break;
           }
       case 24:{strcpy(pr , "Orange Smothie");
            c=60;
            l=strlen(pr);
            break;
           }
       case 25:{strcpy(pr , "Choclate Smothie");
            c=65;
            l=strlen(pr);
            break;
           }
       default:{cout<<"INVALID ENTRY"<<endl;
            strcpy(pr , "INVALID ENTRY");
            c=0;
            l=strlen(pr);
            q=0;
           }
      }
      cout<<"Enter quantity ";
      cin>>q;
      cout<<"Do you want to order anything else"<<endl;
      delay(1000);cout<<"Enter 1 for yes or 2 for no"<<endl;
      cin>>o;
      if(o==2)
      {i=5;
      }
      if(i==0)
      {strcpy(pr1 , pr);
       c1=c;q1=q;l1=l;
      }
      if(i==1)
      {strcpy(pr2 , pr);
       c2=c;q2=q;l2=l;
      }
      if(i==2)
      {strcpy(pr3 , pr);
       c3=c;q3=q;l3=l;
      }
      if(i==3)
      {strcpy(pr4 ,  pr);
       c4=c;q4=q;l4=l;
      }
      if(i==4)
      {strcpy(pr5 , pr);
       c5=c;q5=q;l5=l;
      }
     }
    }
    void bill()
    {long m1,m2,m3,m4,m5,mm;
     m1=q1*c1;m2=q2*c2;m3=q3*c3;m4=q4*c4;m5=q5*c5;mm=m1+m2+m3+m4+m5;
     delay(1000);cout<<"Here is your bill "<<endl;
     delay(1000);
     cout<<"--------------------------------------------------------"<<endl;
     cout<<"                     CYGNETT INN"<<endl;
     cout<<"                     LUCKNOW ROAD"<<endl;
     cout<<"                        HARDOI"<<endl;
     cout<<"                    05852-220015"<<endl;
     cout<<"--------------------------------------------------------"<<endl;
     cout<<"BILL NO.- 48                              DATE- 14/02/18"<<endl;
     cout<<"--------------------------------------------------------"<<endl;
     cout<<"CUSTOMER NAME- "<<nm<<endl;
     cout<<"TOTAL GUESTS- "<<n+1<<endl;
     cout<<"--------------------------------------------------------"<<endl;
     cout<<"PRODUCT               QTY.           RATE         AMOUNT"<<endl;
     cout<<pr1;for(int i=0;i<18-l1;i++){cout<<" ";}cout<<q1<<"            "<<c1<<"         "<<m1;
     cout<<pr2;for(i=0;i<18-l2;i++){cout<<" ";}cout<<q2<<"            "<<c2<<"         "<<m2;
     cout<<pr3;for(i=0;i<18-l3;i++){cout<<" ";}cout<<q3<<"            "<<c3<<"         "<<m3;
     cout<<pr4;for(i=0;i<18-l4;i++){cout<<" ";}cout<<q4<<"            "<<c4<<"         "<<m4;
     cout<<pr5;for(i=0;i<18-l5;i++){cout<<" ";}cout<<q5<<"            "<<c5<<"         "<<m5;
    }
    Last edited by Akshat Agarwal; 01-21-2018 at 08:11 AM.

  2. #2
    Registered User
    Join Date
    Jan 2018
    Posts
    2
    Attachment 15337
    This is the output that I am getting.

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    So I was preparing a program on DOSBOX for school EXAM
    The depths schools will sink to simply to keep TurboC running.... Anyway, your school using an old compiler is probably not your fault. Just make sure that you download one that works for Windows at home.

    My guess is that if the person orders less than 5 items, and then says that they don't want to order more items, you actually don't include the last item that they ordered.

    It's because this:
    Code:
        if (o == 2) {
            i = 5;
        }
    comes before all this.
    Code:
        if (i == 0) {
            strcpy(pr1, pr);
            c1 = c;
            q1 = q;
            l1 = l;
        }
        if (i == 1) {
            strcpy(pr2, pr);
            c2 = c;
            q2 = q;
            l2 = l;
        }
        if (i == 2) {
            strcpy(pr3, pr);
            c3 = c;
            q3 = q;
            l3 = l;
        }
        if (i == 3) {
            strcpy(pr4, pr);
            c4 = c;
            q4 = q;
            l4 = l;
        }
        if (i == 4) {
            strcpy(pr5, pr);
            c5 = c;
            q5 = q;
            l5 = l;
        }
    Once you make i = 5, none of these will be true any more, so you basically skip the last item.

    Mind you, it would make slightly more sense to break; the loop. Your output would still look a little odd, but at least everything bought would be included.

    Finally, your indentation is non-existant. If you really want people to look closely at your code for problems in the future, you need to learn to indent properly.

  4. #4
    Guest
    Guest
    If you compiler supports it, you can also use consecutive string literals to save yourself some more typing:
    Code:
    cout <<
        "First Line\n"
        "Second Line\n"
        "Third Line\n"
    << endl;

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > c1,c2,c3,c4,c5
    What you should have is an array.
    Not putting your own suffix on the end.

    Also, see the FAQ for the following.
    Main returns int, not void
    Iostream.h is obsolete, as is your turbid-c
    Never EVER use gets()
    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.

Popular pages Recent additions subscribe to a feed

Tags for this Thread