Jul 28, 2011 at 9:45pm UTC
The code is finished, however I need somebody to show me how to make it compile, must be missing something...it is a pizza ordering system. How do I make this compile?
#include<iostream>
#include <string>
#include <sstream>
using namespace std;
class PizzaOrder
{
public:
int top[20];
float cost;
float topping_base_cost;
float base_price;
float medium_conv_factor;
private:
int size;
char toppings[20][15];
int num_toppings;
public:
PizzaOrder()
{
num_toppings=0;
size=0;
cost=12.95;
base_price=12.95;
topping_base_cost=2.50;
}
void setsize(char abc)
{
if(abc=='s' || abc=='S')
size=0;
if(abc=='m' || abc=='M')
size=1;
if(abc=='l' || abc=='L')
size=2;
}
void addtopping();
void removetopping()
{
num_toppings=0;
}
void viewpizza();
void calcprice();
};
void PizzaOrder::viewpizza()
{
cout<<"Pizza Details are as follows:"<<endl;
cout<<"Size : "<<size<<endl;
for(int k=0;k<num_toppings;k++)
{
if(top[k]==1)
cout<<"Onions"<<endl;
if(top[k]==2)
cout<<"Bell Peppers"<<endl;
if(top[k]==3)
cout<<"Olives"<<endl;
if(top[k]==4)
cout<<"Pepperoni"<<endl;
}
}
void PizzaOrder::addtopping()
{
char select;
do
{
cout<<"Toppings Offered Are"<<endl;
cout<<"1. Onions, 2. Bell Peppers, 3. Olives, 4. Pepperoni"<<endl;
cin>>top[num_toppings++];
cost=cost+2.50;
cout<<"Want to add More?(Yes-y,No-n):";
cin>>select;
}while(select=='y' || select=='Y');
}
void PizzaOrder::calcprice()
{
cout<<"-----------------------
-----------------"<<endl;
cout<<"\tProduct\t\t\tCost"<<endl;
cout<<"----------------------------------------"<<endl;
cout<<"\tBase Price\t\t"<<base_price<<endl;
for(int k=0;k<num_toppings;k++)
{
if(top[k]==1)
cout<<"\tOnions\t\t\t"<<topping_base_cost<<endl;
if(top[k]==2)
cout<<"\tBell Peppers\t\t"<<topping_base_cost<<endl;
if(top[k]==3)
cout<<"\tOlives\t\t\t"<<topping_base_cost<<endl;
if(top[k]==4)
cout<<"\tPepperoni\t\t"<<topping_base_cost<<endl;
}
if(size==1)
{
cout<<"\tMedium Conversion\t"<<(0.15*cost)<<endl;
cost=cost+(0.15*cost);
}
if(size==2)
{
cout<<"\tLarge Conversion\t"<<(0.25*cost)<<endl;
cost=cost+(0.25*cost);
}
cout<<"----------------------------------------"<<endl;
cout<<"\tTOTAL\t\t\t"<<cost<<endl;
}
void main()
{
char size;
char opt;
PizzaOrder po;
int choice;
do
{
cout<<"Select your P-Pizza OR Enter Q-Quit.."<<endl;
cout<<"Enter your option:";
cin>>opt;
if(opt!='q' && opt!='Q'){
cout<<"Size Available are:"<<endl;
cout<<"Small-S\nMedium-M\nLarge-L"<<endl;
cout<<"Enter Your size Choice:";
cin>>size;
po.setsize(size);
do
{
cout<<"Options Available are:"<<endl;
cout<<"1. Add Topping\n";
cout<<"2. Remove Topping\n";
cout<<"3. View Pizza\n";
cout<<"4. Confirm Order\n";
cout<<"5. QUIT"<<endl;
cout<<"Enter the choice:";
cin>>choice;
switch(choice)
{
case 1: po.addtopping();
break;
case 2: po.removetopping();
break;
case 3: po.viewpizza();
break;
case 4: po.calcprice();
break;
}
}while(choice!=5);
}
else
{
cout<<"\nThank You .."<<endl;
}
}while(opt!='q' && opt!='Q');
}
Jul 28, 2011 at 11:37pm UTC
1) Place it in code tags.
2) Debug it yourself first.
I immediately run it in an IDE and find one instantly, just follow the compiler errors at least.
Last edited on Jul 28, 2011 at 11:39pm UTC
Jul 28, 2011 at 11:40pm UTC
also posting the errors your compiler spitts out will help...
Jul 28, 2011 at 11:41pm UTC
He just has made two mistakes the compiler knows of, fixing these makes it compile.
His main returns void, one of his strings is spanning two lines, I wish people actually attempted to fix their own issues, and not just immediately post every little thing. That's a part of programming I'm afraid.
I believe he stole another person's code, and slapped it together. He couldn't have tested the bulk of the program with a void main().
Last edited on Jul 28, 2011 at 11:44pm UTC
Jul 29, 2011 at 5:37pm UTC
Sorry I wasn't clear with my exact issue, what I meant to say was that I tried compiling and got the error " 'main' must return 'int' " and I don't know how to fix that. Looks like this:
void main()
{ <--- this is where the error occurs
char size;
char opt;
PizzaOrder po;
int choice;
do
Jul 29, 2011 at 5:45pm UTC
Nevermind, I figured it out, thanks