Hi, Im working on a program using a class and im just having a problem with my switch command in my main program. I get an error that says i need a primary expression before int i, such as in:
case'g': p.grow(int i);
But im not quite sure what would go there, this error confuses me. Any help would be very appreciated. Here is my full code for my main program and my class file.
#include <cstdlib>
#include <iostream>
#include "person.h"
usingnamespace std;
int main(int argc, char *argv[])
{
char command;
person p;
p.input ();
cout << "\nEnter one of the following: ";
cout << " e: Enter a persons's statistics";
cout << " g: Grow by a number of inches";
cout << " s: Shrink by a number of inches";
cout << " i: Increase in weight";
cout << " d: Decrease in weight";
cout << " p: Print the current statistics";
cout << " q: Quit the program";
cin >> command;
while (command != 'q')
{
switch (command)
{
case'e': p.input();
break;
case'g': p.grow(int i);
break;
case's': p.shrink(int i);
break;
case'i': p.gain(int w);
break;
case'd': p.lose(int w);
break;
case'p': p.print();
break;
default: cout << "You must enter either e, g, s, i, d, p, or q!";
}
cout << "\nEnter one of the following: ";
cout << " e: Enter a persons's statistics";
cout << " g: Grow by a number of inches";
cout << " s: Shrink by a number of inches";
cout << " i: Increase in weight";
cout << " d: Decrease in weight";
cout << " p: Print the current statistics";
cout << " q: Quit the program";
cin >> command;
}
cout << "\nThank you!!!";
system("PAUSE");
//return EXIT_SUCCESS;
}
Ok, so I tried to make all the changes you suggested. But now I can not get my math to work. For example, in the grow function, I have inches =inches + i, but when i am prompted to add the amount of inches to grow by in my program, the result will be off by a hundred or so. My current inches could be 5, I would add 1, and it would go up to 50..... now I'm really confused
if (inches>12)
{
feet+=inches/12;
inches=inches%12;
}
This needs to be >= since a foot is 12 inches.
I guess the next things are up to you. When you make your person (p.input), you allow for a person to be 0 tall, does that person exist? I would allow for zero values when growing/shinking/gain/lose. If I were using this program to keep track of my height/weight, there would be a lot of times where I grow zero inches. Just ideas.
#include <cstdlib>
#include <iostream>
#include <string>
#include "person.h"
usingnamespace std;
void menu()
{
cout << "\nEnter one of the following: "
<< "\ne: Enter a persons's statistics"
<< "\ng: Grow by a number of inches"
<< "\ns: Shrink by a number of inches"
<< "\ni: Increase in weight"
<< "\nd: Decrease in weight"
<< "\np: Print the current statistics"
<< "\nq: Quit the program"
<<"\n>> ";
}
int main()
{
int i,w;
char command;
person p;
p.input ();
p.print();
menu();
cin >> command;
while (command != 'q')
{
switch (command)
{
case'e':
p.input();
break;
case'g':
//corrected
cout<<endl<<"Enter Number Inches to grow>>";
cin >> i;
p.grow( i);
break;
case's':
//corrected
cout<<endl<<"Enter Number Inches to shrink>>";
cin >> i;
p.shrink(i);
break;
case'i':
//corrected
cout<<endl<<"Enter Number Weight to gain>>";
cin>>w;
p.gain(w);
break;
case'd':
//corrected
cout<<endl<<"Enter Number Weight to shrink>>";
cin>>w ;
p.lose(w);
break;
case'p': p.print();
break;
default: cout << "You must enter either e, g, s, i, d, p, or q!";
}
menu();
cin >> command;
}
cout << "\nThank you!!!";
system("PAUSE");
return 0;
}