Help me figure out the bug in my C++ Code...

Shadowfire

Banned
Aug 25, 2001
382
0
0
This is quite annoying since:
1. We have a sub today...
2. I can't figure it out bymyslef...
3. Help?

The problem is like this; everything goes cool, till the last phase, where it loops itself, and doesn't display letters, but numbers for the pizza diameter *note: compile and run the programm, and ya shall see what i mean*. I tried everything, but still it wont work....
Any ideas on how to fix it?

Code:

//Pizza.cpp
//Gene Romm

#include <iostream>
#include <cstring>
using namespace std;

const int MAX=80;
const int NUM=5;
enum Pizzas{Small, Medium, Large, X_Large};
struct pizza
{
char name[MAX];
Pizzas diameters;
double weight;

};



void getName(pizza ar[], int i);
void getDiameter(pizza ar[], int x);
void getWeight(pizza ar[], int m);
void showall(pizza ar[], int i);



int main()
{
pizza company
  1. ;

    for (int i=0; i<NUM; i++)
    {
    getName(company, i);
    getDiameter(company, i);
    getWeight(company, i);
    showall(company, i);
    }


    return 0;
    }


    void getName(pizza ar[], int i)
    {
    cout << "What is your company's name? ";
    cin.getline(ar.name, MAX);
    return;
    }

    void getDiameter(pizza ar[], int x)
    {
    char Small=1;
    char Medium=2;
    char Large=3;
    char X_Large=4;
    cout<<"Please the number for the corresponding diamteres of the pizza:\n";
    cout<<"1 - Small\n";
    cout<<"2 - Medium\n";
    cout<<"3 - Large\n";
    cout<<"4 - X_Large\n";
    cin>>x;
    {
    if (x==1)
    cout<<"Your pizza is going to be small!\n";
    else if (x==2) cout<<"Your pizza is going to be medium-sized!\n";
    else if (x==3) cout<<"Your pizza is going to be quite large!\n";
    else if (x==4) cout<<"You sure you want this huge thing for dinner...?\n";
    }
    return;
    }

    void getWeight(pizza ar[], int i)
    {



    cout<<"Now would you please enter the weight for your pizza in pounds?";
    cin >> ar.weight;


    return;
    }

    void showall(pizza ar[], int i)
    {
    cout<<"\n";
    cout<<"Lets see, your company's name is "<<ar.name <<",\n";
    cout<<"Your prefered pizza size is "<<ar.diameters <<", \n";
    cout<<"And the weight of the pizza is "<<ar.weight <<".\n";

    return;
    }









 

EagleKeeper

Discussion Club Moderator<br>Elite Member
Staff member
Oct 30, 2000
42,589
5
0
What happens if you make the diameter an pointer into the enum array of pizza sizes.

You presently are dumping the diameter index, not the array value.
 

notfred

Lifer
Feb 12, 2001
38,241
4
0
when I tried to compile it:

[C++ Error] APP.cpp(35): E2034 Cannot convert 'pizza' to 'pizza *'
[C++ Error] APP.cpp(35): E2342 Type mismatch in parameter 'ar' (wanted 'pizza *', got 'pizza')
[C++ Error] APP.cpp(36): E2034 Cannot convert 'pizza' to 'pizza *'
[C++ Error] APP.cpp(36): E2342 Type mismatch in parameter 'ar' (wanted 'pizza *', got 'pizza')
[C++ Error] APP.cpp(37): E2034 Cannot convert 'pizza' to 'pizza *'
[C++ Error] APP.cpp(37): E2342 Type mismatch in parameter 'ar' (wanted 'pizza *', got 'pizza')
[C++ Error] APP.cpp(38): E2034 Cannot convert 'pizza' to 'pizza *'
[C++ Error] APP.cpp(38): E2342 Type mismatch in parameter 'ar' (wanted 'pizza *', got 'pizza')
[C++ Error] APP.cpp(49): E2294 Structure required on left side of . or .*
[C++ Error] APP.cpp(49): E2285 Could not find a match for 'istream::getline(undefined,const int)'
[C++ Warning] APP.cpp(73): W8004 'X_Large' is assigned a value that is never used
[C++ Warning] APP.cpp(73): W8004 'Large' is assigned a value that is never used
[C++ Warning] APP.cpp(73): W8004 'Medium' is assigned a value that is never used
[C++ Warning] APP.cpp(73): W8004 'Small' is assigned a value that is never used
[C++ Error] APP.cpp(81): E2294 Structure required on left side of . or .*
[C++ Error] APP.cpp(90): E2294 Structure required on left side of . or .*
[C++ Error] APP.cpp(91): E2294 Structure required on left side of . or .*
[C++ Error] APP.cpp(92): E2294 Structure required on left side of . or .*



I'm certainly not going through all that :)
 

br0wn

Senior member
Jun 22, 2000
572
0
0
Here are three errors that I spotted (no, I haven't compile
your program yet):

1. You created just one pizza structure (company). This
is an error, you should have created an array
of pizza structure (i.e. pizza[ NUM ] company).

2. In the functions getName, getDiameter, getWeight, and
showAll, 'ar' is an array of pizza, but you are accessing
it as it is only a pizza structure.
To correct it: you should have something like
ar[ i ] in there.

3. getWeight function is wrong.
You should have input the weight into the array
(i.e cin >> ar[ i ].weight)