Click here to Skip to main content
15,889,034 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i am making a c++ program of hotel management system.I want that the user will enter product number and quantity.After writing, the program will ask if the user wants to order any other product if he write 'y'the program should again ask to enter product number and quantity.It should continue while user wants.
When the user writes 'n'instead of 'y'
the program should show the total amount.Also it should show which product i have order and quantity and total rupess for each of them in bill and at last it should show the net amount.

What I have tried:

C++
#include<iostream.h>                  
#include<conio.h>
void main()
{
clrscr();
start:
cout<<"--------------------------------HOTEL RED CHILLIES------------------------------" ;
cout<<"                             M.G.ROAD RAIPUR - 492001";
cout<<"\n\t\t\t\tPHONE: 0771-4024196";
cout<<"\n--------------------------------------------------------------------------------";

cout<<"*CATEGORIES*\t\tPrice\t\t *CATEGORIES*\t\tPrice"  ;

cout<<"\n\nChinese Noodles\t\t\t Pizza";
cout<<"\n\n1.Veg Chowmein\t\t 100 \t\t 7.Red Green Pizza\t 160";
cout<<"\n2.Chili Garlic Noodles\t 100\t\t 8.Deluxe Margherita\t 180";
cout<<"\n3.American Chop Suey\t 110\t\t 9.Tomato Deluxe\t 180";

cout<<"\n------------------------------\t\t -----------------------------";

cout<<"\n\nPasta\t\t\t\t\t Soup";
cout<<"\n\n4.Pasta Red Sauce\t 160\t\t 10.Hot and Sour\t 70";
cout<<"\n5.Pasta Mexican\t\t 160\t\t 11.Tomato Soup\t\t 70";
cout<<"\n6.Pasta White Sauce\t 170\t\t 12.Manchow Soup\t 70";

cout<<"\n-------------------------------\t\t -----------------------------";
int num,qt,i=0,t,sum;
char pro;

do
{cout<<"\nEnter the product number(1-12)- ";
cin>>num;
cout<<"\nEnter the quantity- ";
cin>>qt;
switch(num)
{
case 1: t=100*qt;
case 2: t=100*qt;
case 3: t=100*qt;
case 4: t=100*qt;
case 5: t=100*qt;
case 6: t=100*qt;
case 7: t=100*qt;
case 8: t=100*qt;
case 9: t=100*qt;
case 10: t=100*qt;
case 11: t=100*qt;
case 12: t=100*qt;
}

cout<<"\nDo you want to order any other product(y/n) ";
cin>>pro;

if(pro=='y')
{
clrscr();
goto start;

}
}
while(pro=='y');
do{
for(t=1; ;t++)
sum=t;}
while(pro=='y') ;
if(pro=='n')
cout<<"total is"<<sum;
Posted
Updated 6-Feb-18 23:58pm
v2
Comments
OriginalGriff 7-Feb-18 2:26am    
And?
What does it do that you didn't expect, or not do that you did?
What have you tried to find out why?
Where are you stuck?
What help do you need?
Member 13665211 7-Feb-18 2:30am    
i have used do while statement.
in last i am rying to use do while statement to calculate the total forall

Don't use goto, you don't really need it.
Don't use such an ancient compiler (conio.h has gone long time ago).
Do use structured data.
Do use STL containers.

A C++98 implementation sketch
C++
#include <iostream>
#include <vector>

using namespace std;


struct Product
{
  string desc;
  int price;
  Product(string desc, int price):desc(desc), price(price){}
};


void show_menu(const vector<Product> & vp);

int main()
{
  vector <Product> vp;

  vp.push_back(Product("Veg Chowmein", 100));
  vp.push_back(Product("Chili Garlic Noodles", 110));
  // add more products...


  int sum = 0;

  while (true)
  {
    show_menu(vp);
    int index, qty;
    cin >> index;
    if ( index == -1) break;
    --index;
    if ( index >= 0 && index < static_cast<int>(vp.size()) )
    {
      cout << "please enter quantity" << endl;
      cin >> qty;
      sum += (qty * vp[index].price);
    }
  }
  cout << "the sum is " << sum << endl;
}


void show_menu( const vector<Product> & vp)
{
  cout << "please choose product (-1 to exit)" << endl;
  for (size_t n=0; n<vp.size(); ++n)
  {
    const Product & p = vp[n];
    cout << (n+1) << " " << p.desc << " " << p.price << endl;
  }
}


[update]
Using an array instead of std::vector
C++
#include <iostream>

using namespace std;

struct Product
{
  string desc;
  int price;
  Product(string desc, int price):desc(desc), price(price){}
};

void show_menu( Product ap[], int ITEMS);

int main()
{
  Product ap[] = { 
     Product("Veg Chowmein", 100), 
     Product("Chili Garlic Noodles", 110)
  };
  // add more products..

  const int ITEMS = sizeof(ap)/sizeof(ap[0]);

  int sum = 0;

  while (true)
  {
    show_menu(ap, ITEMS);
    int index, qty;
    cin >> index;
    if ( index == -1) break;
    --index;
    if ( index >= 0 && index <ITEMS )
    {
      cout << "please enter quantity" << endl;
      cin >> qty;
      sum += (qty * ap[index].price);
    }
  }
  cout << "the sum is " << sum << endl;
}


void show_menu( Product ap[], int ITEMS)
{
  cout << "please choose product (-1 to exit)" << endl;
  for (int n=0; n<ITEMS; ++n)
  {
    const Product & p = ap[n];
    cout << (n+1) << " " << p.desc << " " << p.price << endl;
  }
}

[/update]
 
Share this answer
 
v2
Comments
Member 13665211 7-Feb-18 4:34am    
actually i am a student of class 11.I have not studied vector.So please can u make this in conio.h form.
CPallini 7-Feb-18 5:47am    
I've just updated my solution, now there is a version with array instead of std::vector...
Member 13665211 7-Feb-18 6:38am    
please can u make the same in another method by using basics like do while,if,switch,etc basic
CPallini 7-Feb-18 7:22am    
Sorry, that IS basic already.
Member 13665211 10-Feb-18 1:41am    
i have created this code
can u help me to get the grandtotal of all the product and quantity
#include<iostream.h> 7
#include<conio.h>
int calculate(int quantity, int price)
{
// this is an oversimplification of a function

int tot = quantity * price;
return tot; }
void main()
{
clrscr();
start:
cout<<"--------------------------------HOTEL RED CHILLIES------------------------------" ;
cout<<" M.G.ROAD RAIPUR - 492001";
cout<<"\n\t\t\t\tPHONE: 0771-4024196";
cout<<"\n--------------------------------------------------------------------------------";

cout<<"*CATEGORIES*\t\tPrice\t\t *CATEGORIES*\t\tPrice" ;

cout<<"\n\nChinese Noodles\t\t\t Pizza";
cout<<"\n\n1.Veg Chowmein\t\t 100 \t\t 7.Red Green Pizza\t 160";
cout<<"\n2.Chili Garlic Noodles\t 100\t\t 8.Deluxe Margherita\t 180";
cout<<"\n3.American Chop Suey\t 110\t\t 9.Tomato Deluxe\t 180";

cout<<"\n------------------------------\t\t -----------------------------";

cout<<"\n\nPasta\t\t\t\t\t Soup";
cout<<"\n\n4.Pasta Red Sauce\t 160\t\t 10.Hot and Sour\t 70";
cout<<"\n5.Pasta Mexican\t\t 160\t\t 11.Tomato Soup\t\t 70";
cout<<"\n6.Pasta White Sauce\t 170\t\t 12.Manchow Soup\t 70";

cout<<"\n-------------------------------\t\t -----------------------------";
int num,qt,total;
char pro;
int grandtotal;
grandtotal=0;
do
{cout<<"\nEnter the product number(1-12)- ";
cin>>num;
switch(num)
{
case 1: cout<<"\nEnter the quantity- ";
cin>>qt;
total=100*qt;

break;
case 2: cout<<"\nEnter the quantity- ";
cin>>qt;
total=100*qt;

break;
case 3: cout<<"\nEnter the quantity- ";
cin>>qt;
total=110*qt;

break;
case 4: cout<<"\nEnter the quantity- ";
cin>>qt;
total=160*qt;

break;
case 5: cout<<"\nEnter the quantity- ";
cin>>qt;
total=160*qt;

break;
case 6: cout<<"\nEnter the quantity- ";
cin>>qt;
total=170*qt;

break;
case 7: cout<<"\nEnter the quantity- ";
cin>>qt;
total=160*qt;

break;
case 8: cout<<"\nEnter the quantity- ";
cin>>qt;
total=180*qt;

break;
case 9: cout<<"\nEnter the quantity- ";
cin>>qt;
total=180*qt;

break;
case 10: cout<<"\nEnter the quantity- ";
cin>>qt;
total=70*qt;

break;
case 11: cout<<"\nEnter the quantity- ";
cin>>qt;
total=70*qt;

break;
case 12: cout<<"\nEnter the quantity- ";
cin>>qt;
total=70*qt;

break;
}


cout<<"\nDo you want to order any other product(y/n) ";
cin>>pro;

if(pro=='y')
{
clrscr();
goto start;




}
grandtotal=grandtotal+total;

}
while(pro=='y');




if(pro=='n')
cout<<"total is"<<grandtotal;










getch();
}
C++
cin>>qt;
switch(num)
{
case 1: t=100*qt;
case 2: t=100*qt;
case 3: t=100*qt;
case 4: t=100*qt;
case 5: t=100*qt;
case 6: t=100*qt;
case 7: t=100*qt;
case 8: t=100*qt;
case 9: t=100*qt;
case 10: t=100*qt;
case 11: t=100*qt;
case 12: t=100*qt;
}

What is the point of this switch block, since every case calculates the same value? And since you have no break statements you just repeat the same calculation up to 12 times.
 
Share this answer
 
Comments
Member 13665211 7-Feb-18 4:31am    
no i have not edited the price.I just copied 12 times for 12 products.When the program will be made i will just rename
Richard MacCutchan 7-Feb-18 4:52am    
Well that code is still wrong.
Member 13665211 7-Feb-18 5:59am    
please can u send me the exact code
Member 13665211 7-Feb-18 6:01am    
please can u send me.the exact code
Member 13665211 7-Feb-18 6:40am    
i have uploaded the whole code which i have made.Please can u send me the afterward code..You can make any changes
You need to learn the usage of break in a switch statement.
-----
Learn to indent properly your code, it show its structure and it helps reading and understanding. It also helps spotting structures mistakes.
C++
while(pro=='y');
do{
    for(t=1; ;t++)
sum=t;
}
while(pro=='y') ;
if(pro=='n')
    cout<<"total is"<<sum;

Professional programmer's editors have this feature and others ones such as parenthesis matching and syntax highlighting.
Notepad++ Home[^]
ultraedit[^]
-----
There is a tool that allow you to see what your code is doing, its name is debugger. It is also a great learning tool because it show you reality and you can see which expectation match reality.
When you don't understand what your code is doing or why it does what it does, the answer is debugger.
Use the debugger to see what your code is doing. Just set a breakpoint and see your code performing, the debugger allow you to execute lines 1 by 1 and to inspect variables as it execute.

Debugger - Wikipedia, the free encyclopedia[^]

Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]
Basic Debugging with Visual Studio 2010 - YouTube[^]
The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to. When the code don't do what is expected, you are close to a bug.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900