Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
10/10/2009 2:28:53 PM EDT
This is almost working I just need help with the getData definition
should be easy but i keep getting errors



#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

struct menuItemType
{
string menuItem;
double menuPrice;
int numOrdered;
};
menuItemType theMenu;

void showMenu();
int getData(int choice);
double Round(double &totalTax);
void printCheck(double &tax, double &totalBill);


int main()
{
int choice=0; //The number the user chooses for the item they want
int number=0; // Used in the getData function
int x=0; // used in "for" loop to initialize numOrdered to 0.
double bill = 0.0;
double totalBill = 0.0; //  w/ tax
double tax = 0.0;  
double taxRate = .05; // tax%
double totalTax =0.0;
char shouldContinue;


theMenu[0].menuItem  = "#1  Plain Egg";
theMenu[1].menuItem  = "#2  Bacon and Egg";
theMenu[2].menuItem  = "#3  Muffin";
theMenu[3].menuItem  = "#4  French Toast";
theMenu[4].menuItem  = "#5  Fruit Basket";
theMenu[5].menuItem  = "#6  Cereal";
theMenu[6].menuItem  = "#7  Coffee";
theMenu[7].menuItem  = "#8  Tea";

theMenu[0].menuPrice  = 1.45;
theMenu[1].menuPrice  = 2.45;
theMenu[2].menuPrice  = 0.99;
theMenu[3].menuPrice  = 1.99;
theMenu[4].menuPrice  = 2.49;
theMenu[5].menuPrice  = 0.69;
theMenu[6].menuPrice  = 0.50;
theMenu[7].menuPrice  = 0.75;

for (x = 0; x < 8; x++) // Initialize theMenu.numOrdered to all 0's.  
{
theMenu.numOrdered = 0;
}

do
{
showMenu();  // run the void showMenu() function
cout << "\n" << endl;

choice = getData(number); // Returns the number the person chose the the array number

bill = theMenu[choice].menuPrice + bill; // Keeps a running total of the bill

theMenu[choice].numOrdered++; //Add 1 to the amount of the item ordered.  

cout << "\n" << theMenu[choice].numOrdered << setw (20) << theMenu[choice].menuItem << " \n" << endl;

cout << "Would you like to place another order?  (Y/N)" << endl; // Allow to purchase more
cin >> shouldContinue;
}
while (shouldContinue == 'Y' || shouldContinue == 'y');
cout << endl;

totalTax = bill * taxRate;

tax = Round(totalTax);

totalBill = bill + tax;

printCheck(tax, totalBill);

return 0;
}



void showMenu()
{
int x;
for (x = 0; x <=7; x++)
cout << theMenu.menuItem << "\t" << theMenu.menuPrice << endl;
}


////////////////////////getData
int choice = -1;
while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));
{
  showMenu();  // run the void showMenu() function
  cout << "\n" << choice << endl;
  choice = getData(number); // Returns the number the person chose the the array number
  }


double Round(const double &totalTax) //Round to the nearest cent.  
  {
double tax;
 
tax = totalTax * 100.0 + 0.5;
return tax / 100.0;
  }

void printCheck(double &tax, double &totalBill)
{
int x;
x = 0;

cout << "Welcome \n" << endl;
for (x = 0; x < 8; x++)
{
if (theMenu.numOrdered > 0)
{
cout << theMenu.numOrdered << "\t" << theMenu.menuItem << "\t" << right << theMenu.menuPrice << right << endl;
}
else
{
cout << "";
}
}

cout << "Tax" << setw (27) << tax << endl;
cout << "Amount Due" << setw (20) << totalBill << endl;
}
10/10/2009 2:36:27 PM EDT
[#1]
I don't have my compiler installed on this system.

What/where are the errors and can you resubmit without the smiles?
10/10/2009 2:38:56 PM EDT
[#2]
they start right where i have /////////////////////getdata

1>p:\comp220\test\test\imp.cpp(98) : error C2144: syntax error : 'int' should be preceded by ';'
1>p:\comp220\test\test\imp.cpp(98) : error C2365: 'getData' : redefinition; previous definition was 'function'
1>        p:\comp220\test\test\imp.cpp(16) : see declaration of 'getData'
1>p:\comp220\test\test\imp.cpp(99) : error C2059: syntax error : 'while'
1>p:\comp220\test\test\imp.cpp(100) : error C2447: '{' : missing function header (old-style formal list?)




int getData
int choice = -1;
while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));
{
  showMenu();  // run the void showMenu() function
  cout << "\n" << choice << endl;
  choice = getData(number); // Returns the number the person chose the the array number
  }


10/10/2009 2:39:48 PM EDT
[#3]
I can always tell when school is back in session.
10/10/2009 2:41:22 PM EDT
[#4]
int x;
Int y;
int z;
int main ()
{
     z= 0;
     y = z;
      x/y;

   return ZOMG;
}

10/10/2009 2:42:26 PM EDT
[#5]
Quoted:
they start right where i have
/////////////////////getdata


1>p:\comp220\test\test\imp.cpp(98) : error C2144: syntax error : 'int' should be preceded by ';'
1>p:\comp220\test\test\imp.cpp(98) : error C2365: 'getData' : redefinition; previous definition was 'function'
1>        p:\comp220\test\test\imp.cpp(16) : see declaration of 'getData'
1>p:\comp220\test\test\imp.cpp(99) : error C2059: syntax error : 'while'
1>p:\comp220\test\test\imp.cpp(100) : error C2447: '{' : missing function header (old-style formal list?)



int getDataint choice = -1;while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));{   showMenu();  // run the void showMenu() function   cout << "\n" << choice << endl;   choice = getData(number); // Returns the number the person chose the the array number   }



The part after /////////////////////getdata kind of needs to be in a function or something.
10/10/2009 2:43:49 PM EDT
[#6]
its a definition??
10/10/2009 2:44:28 PM EDT
[#7]
The example you pasted is not a function.
10/10/2009 2:45:24 PM EDT
[#8]
You don't have getData written as a function.  You declared it but just left it inline in the function above it.
10/10/2009 2:46:00 PM EDT
[#9]
right duh


int getData()
{
int choice = -1;
while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));
{
                    showMenu();  // run the void showMenu() function
                    cout << "\n" << choice << endl;
                    choice = getData(number); // Returns the number the person chose the the array number
}
}


now just  error C2065: 'number' : undeclared identifier


.
10/10/2009 2:46:22 PM EDT
[#10]
Not to mention that number is not defined in that scope. choice is apparently a function parameter and should probably not be declared like that nor initialized to -1.

ETA: And your prototype says that getData should take an int parameter and will return an int, not void.
10/10/2009 2:49:05 PM EDT
[#11]
how should number be defined?
10/10/2009 2:50:22 PM EDT
[#12]
Quoted:
how should number be defined?


It's your program, you tell me. You're simply saying "number" without ever having done anything with it in that scope. I don't know what it's supposed to be (aside from that in that context, it should be an int).
10/10/2009 2:50:24 PM EDT
[#13]
NVM, it has been covered already.  I'm so far out of practice.  
10/10/2009 2:53:56 PM EDT
[#14]

int getData()
{
int choice = 0;
while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));
{
  showMenu();  // run the void showMenu() function
  cout << "\n" << choice << endl;
  choice = getData(choice); // Returns the number the person chose the the array number
}
}

: error C4716: 'getData' : must return a value
god i suck at this
10/10/2009 2:54:49 PM EDT
[#15]





Quoted:



they start right where i have /////////////////////getdata





1>p:\comp220\test\test\imp.cpp(98) : error C2144: syntax error : 'int' should be preceded by ';'


1>p:\comp220\test\test\imp.cpp(98) : error C2365: 'getData' : redefinition; previous definition was 'function'


1>        p:\comp220\test\test\imp.cpp(16) : see declaration of 'getData'


1>p:\comp220\test\test\imp.cpp(99) : error C2059: syntax error : 'while'


1>p:\comp220\test\test\imp.cpp(100) : error C2447: '{' : missing function header (old-style formal list?)
int getDataint choice = -1;while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));{   showMenu();  // run the void showMenu() function   cout << "\n" << choice << endl;   choice = getData(number); // Returns the number the person chose the the array number   }






Uhh...





Your 'int getData' defines an integer variable named getData....





You should have an:





int getdata (int choice)


{


// Function code goes here


}





But what you have, is:





int getData




int choice


{


}
 
10/10/2009 2:56:34 PM EDT
[#16]

int getData(int choice)
{

while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));
{
  showMenu();  // run the void showMenu() function
  cout << "\n" << choice << endl;
  choice = getData(??????????); // Returns the number the person chose the the array number
}
}


should be the last piece of the puzzle?
10/10/2009 2:58:37 PM EDT
[#17]
Well, your while loop is also incorrectly defined. A semi-colon at the end is interpreted as a null statement. The code between the curly braces isn't part of the loop.

You're also recursively calling getData. I hope you know what you're doing, otherwise you're bound to encounter a case of infinite recursion and probably a stack overflow.
10/10/2009 2:58:49 PM EDT
[#18]



Quoted:



int getData(){int choice = 0;while(choice < 0 || choice > sizeof(theMenu)/sizeof(menuItemType));{   showMenu();  // run the void showMenu() function   cout << "\n" << choice << endl;   choice = getData(choice); // Returns the number the person chose the the array number}}


: error C4716: 'getData' : must return a value

god i suck at this


yes...



Not only did you create a 'GetData' function without a 'getData =' at the end....



But you will have some real 'fun' if you try to run the above code-snippet once you add one...



2 words: Infinite Loop





 
10/10/2009 3:00:05 PM EDT
[#19]
Quoted:
Well, your while loop is also incorrectly defined. A semi-colon at the end is interpreted as a null statement. The code between the curly braces isn't part of the loop.

You're also recursively calling getData. I hope you know what you're doing, otherwise you're bound to encounter a case of infinite recursion and probably a stack overflow.



typo
and no....sadly i dont
10/10/2009 3:02:41 PM EDT
[#20]
Quoted:
Quoted:
Well, your while loop is also incorrectly defined. A semi-colon at the end is interpreted as a null statement. The code between the curly braces isn't part of the loop.

You're also recursively calling getData. I hope you know what you're doing, otherwise you're bound to encounter a case of infinite recursion and probably a stack overflow.



typo
and no....sadly i dont


Well, enjoy a crash course in debugging code that compiles but doesn't run.