I am doing this program that has a menu of 8 items
The error is:

--------------------Configuration: aaaaa - Win32 Debug--------------------
Compiling...
aaaaa.cpp
c:\temp\test\test1\aaaaa.cpp(125) : error C2374: 'x' : redefinition; multiple initialization
c:\temp\test\test1\aaaaa.cpp(120) : see declaration of 'x'
Error executing cl.exe.

aaaaa.exe - 1 error(s), 0 warning(s)

Does anyone know where is the error ?
Thanks

// program description: This program help a local restaurant automate its breakfast
// billing system.
// It show the customer the different items available, allow
// the customer to selectmore than one item from the menu,
// calculates and print the bill.

// include all libraries

#include<iostream> 
#include<string> 
#include<iomanip> 

void showMenu(); 
using namespace std; 

const int menu = 1; 

struct menuItemType 
{ 
   string menuItem; 
   double menuPrice; 
}; 

void getData(menuItemType placeorder[8]); 
void printCheck(menuItemType printorder[]); 

int main() 
{ 
   showMenu(); 
   //menuItemType menuList[8]; 
   menuItemType order[8]; 
   getData(order); 
   printCheck(order); 

   /*int choices=[8] 
   //int choiceType; 
   double tax; 
   double amountDue; 
   menuItemType menuList[8] 
   getData(menuList);*/ 

   return 0; 
} 

/////////Shows different items offered and how to order/////////////// 
void showMenu() 
{ 
   cout <<"-------------------------------------------------"<<endl; 
   cout <<"           Please place your order:              "<<endl; 
   cout <<"-------------------------------------------------"<<endl; 
   cout <<"1. Plain Egg..............$1.45 "<<endl; 
   cout <<"2. Bacon and Egg..........$2.45 "<<endl; 
   cout <<"3. Muffin.................$0.99 "<<endl; 
   cout <<"4. French Toast...........$1.99 "<<endl; 
   cout <<"5. Fruit Basket...........$2.49 "<<endl; 
   cout <<"6. Cereal.................$0.69 "<<endl; 
   cout <<"7. Coffee.................$0.50 "<<endl; 
   cout <<"8. Tea....................$0.75 "<<endl; 
   cout <<"------------------------------------------------"<<endl; 
} 

/////////////////////Loads data into the array////////////////////// 
void getData(menuItemType placeorder[8]) 
{ 
   menuItemType menuList[8]; 
   menuList[0].menuItem ="Plain Egg";      
   menuList[1].menuItem ="Bacon and Egg"; 
   menuList[2].menuItem ="Muffin";          
   menuList[3].menuItem ="French Toast";      
   menuList[4].menuItem ="Fruit Basket"; 
   menuList[5].menuItem ="Cereal"; 
   menuList[6].menuItem ="Coffee"; 
   menuList[7].menuItem ="Tea"; 

   menuList[0].menuPrice =1.45; 
   menuList[1].menuPrice =2.45; 
   menuList[2].menuPrice=0.99; 
   menuList[3].menuPrice=1.99; 
   menuList[4].menuPrice=2.49; 
   menuList[5].menuPrice=0.69; 
   menuList[6].menuPrice=0.50; 
   menuList[7].menuPrice=0.75;  
   for(int x=0;x<2;x++) 
   { 
      cout << "What do you want chose 1 thought 8: " << endl; 
      int answer; 
      cin >> answer; 
      cout << "How many : " << endl; 
      int howmany; 
      cin >> howmany; 

      placeorder[x].menuItem = menuList[answer-1].menuItem; 
      placeorder[x].menuPrice = menuList[answer-1].menuPrice *howmany; 
   } 
} 

////////////Calulates and prints the check///////////////////// 
void printCheck(menuItemType printorder[]) 
{ 
   //double tax = .05; 
   // double amountDue=0; 

   int x=0; 

   cout <<"-------------------------------------------------"<<endl; 
   cout<<"       Welcome to Johnny's Restaurant"<<endl; 
   cout <<"-------------------------------------------------"<<endl; 
   for(int x=0;x<2;x++) 
   { 
   cout<<printorder[x].menuItem<<setw(8)<<printorder[x].menuPrice<<endl; 
   //cout<<menuList[x].menuItem<<setw(8)<<menuList[x].menuPrice<<endl; 
   //cout<<menuList[x].menuItem<<setw(8)<<menuList[x].menuPrice<<endl; 
   } 
   //cout<<"Tax................$"<<tax<<endl; 
   //cout<<"Amount Due.........$"<<amtDue<<endl;  
}
////////////Calulates and prints the check/////////////////////
void printCheck(menuItemType printorder[])
{
   //double tax = .05;
   // double amountDue=0;

   int x=0;

   cout <<"-------------------------------------------------"<<endl;
   cout<<"       Welcome to Johnny's Restaurant"<<endl;
   cout <<"-------------------------------------------------"<<endl;
   for(int x=0;x<2;x++)
   {
   cout<<printorder[x].menuItem<<setw(8)<<printorder[x].menuPrice<<endl;
   //cout<<menuList[x].menuItem<<setw(8)<<menuList[x].menuPrice<<endl;
   //cout<<menuList[x].menuItem<<setw(8)<<menuList[x].menuPrice<<endl;
   }
   //cout<<"Tax................$"<<tax<<endl;
   //cout<<"Amount Due.........$"<<amtDue<<endl;
}

Thanks Davie.

Now I am facing another problem that I can figure out the solution. I already did research on books but do not find the solution for thi.
I am trying to get the total tax amount based on the items that the user is selecting. The taxRate is .05 of the subtotal. I just can get the tax of the last item. How can I get the tax of the 2 items instead of just the last one ?
My input is 1, 2, 3 and 4 (item 1 x 2 and item 3 x 4).
Could you help me please?

#include <iostream> 
#include <string> 
#include <iomanip> 

void showMenu(); 

using namespace std; 

const int menu = 1; 

struct menuItemType 

{ 
   string menuItem; 
   double menuPrice; 
}; 

void getData(menuItemType placeorder[8]); 
void printCheck(menuItemType printorder[]); 

int main() 

{ 
   showMenu(); 
   menuItemType menuList[8]; 
   menuItemType order[8]; 
   getData(order); 
   printCheck(order); 

   int choices = 8; 
  
   return 0; 
} 

// MENU
 
void showMenu() 
{ 
	cout << "===============================================" << endl; 
	cout << "	   Johnny's Restaurant - MENU               " << endl; 
	cout << "===============================================" << endl; 
	cout << "       1.Plain Egg.................$ 1.45	    " << endl; 
	cout << "       2.Bacon and Egg.............$ 2.45	    " << endl; 
	cout << "       3.Muffin....................$ 0.99	    " << endl; 
	cout << "       4.French Toast..............$ 1.99	    " << endl; 
	cout << "       5.Fruit Basket..............$ 2.49	    " << endl; 
	cout << "       6.Cereal....................$ 0.69	    " << endl; 
	cout << "       7.Coffee....................$ 0.50	    " << endl; 
	cout << "       8.Tea.......................$ 0.75	    " << endl; 
	cout << "===============================================" << endl; 
} 

// puts data into the array
 
void getData(menuItemType placeorder[8]) 
{ 
	menuItemType menuList[8]; 
	menuList[0].menuItem = "     Plain Egg     ";      
	menuList[1].menuItem = "     Bacon and Egg "; 
	menuList[2].menuItem = "     Muffin        ";          
	menuList[3].menuItem = "     French Toast  ";      
	menuList[4].menuItem = "     Fruit Basket  "; 
	menuList[5].menuItem = "     Cereal        "; 
	menuList[6].menuItem = "     Coffee        "; 
	menuList[7].menuItem = "     Tea           "; 

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

	for (int x=0; x<2; x++) 
   { 
	cout << endl;
	cout << "Please choose an item from the MENU:          "; 
    int answer; 
    cin >> answer; 
    cout << "Please especify the quantity you want:        "; 
    int howmany; 
    cin >> howmany; 

    placeorder[x].menuItem = menuList[answer-1].menuItem; 
    placeorder[x].menuPrice = menuList[answer-1].menuPrice * howmany; 
   } 
} 

// calculates and prints the RECEIPT
 
void printCheck(menuItemType printorder[]) 
{ 
	const double taxRate = 0.05; 
	int x = 0;
	double amtDue = 0;
	double tax; 
	
	cout << endl;
	cout << endl;
	cout << endl;

	cout << "     ================================== " << endl; 
	cout << "               R E C E I P T !          " << endl; 
	cout << "     ================================== " << endl; 
	cout << "       WELCOME TO JOHNNY'S RESTAURANT   " << endl; 
	cout << "     ================================== " << endl; 
	cout << endl;

	for (x=0; x<2; x++) 
	{ 
	cout.precision(3);
	cout << showpoint;
	tax = (printorder[x].menuPrice) * taxRate; // HERE IS THE PROBLEM
	cout << printorder[x].menuItem << setw(16) << "$ " << printorder[x].menuPrice << endl; 
	}

	cout.precision(1);
	cout << showpoint;
	cout<<"     Tax                         $ " << tax << endl; 
	cout.precision(2);
	cout << showpoint;
	cout<<"     Amount Due                  $ " << amtDue << endl;

	cout << endl;
	cout <<"     ================================== " << endl; 
	cout <<"          T H A N K    Y O U  !!!!      " << endl; 
	cout <<"     ================================== " << endl; 
	cout << endl;
	cout << endl;

}

You probably want;
tax += (printorder[x].menuPrice) * taxRate

rather than
tax = (printorder[x].menuPrice) * taxRate

(otherwise, you end up resetting tax each time through the loop)

Ok. I changed and endup w/ this ?
Tax $ -9.e+061
Now is just a matter of formatting the output tax ?
Thanks for the help

Tell me what you 'ordered', so that I can try the same here.. Also, you're setting you're precision to 1, set it to something higher...

I ordered:
2 x Plain Egg and 4 x Muffin
Input 1, 2, 3 and 4.
Please choose an item from the MENU: 1
Please especify the quantity you want: 2

Please choose an item from the MENU: 3
Please especify the quantity you want: 4

==================================
R E C E I P T !
==================================
WELCOME TO JOHNNY'S RESTAURANT
==================================

Plain Egg $ 2.90
Muffin $ 3.96
Tax $ -9.e+061
Amount Due $ 0.00

==================================
T H A N K Y O U !!!!
==================================

Try 2 things:

When setting your price, put them in with F (ie:
menuList[0].menuPrice = 1.45F;


Also, set a higher precision before printing the tax.


Please choose an item from the MENU: 1
Please especify the quantity you want: 2
Please choose an item from the MENU: 3
Please especify the quantity you want: 4

==================================
R E C E I P T !
==================================
WELCOME TO JOHNNY'S RESTAURANT
==================================
TAX:0.145
Plain Egg $ 2.90
TAX:0.343
Muffin $ 3.96
Tax $ 0.3430
Amount Due $ 0.0
==================================
T H A N K Y O U !!!!
==================================

I still don't get it.
I did change the precision but the F thing I did not understood.
Is there any other way ?

(Actually, you probably don't need or want the F since you declared it as a double. If you changed the tax calculation to be += and the precision to be at least 3, did you get the right answer?)

No. I still receive this.
-9.3e+061
Sorry to bother you with this, but I really need to get this fixed and most important, need to understand why this is happening.
THANKS

I changed now to
tax =+ (printorder[x].menuPrice) * taxRate;
instead of
tax += (printorder[x].menuPrice) * taxRate;
and the result of tax is 0.20 (is just taking into consideration the last item choosen and NOT both).
Remember, the input was 1, 2, 3 and 4. Meaning that 2 x Items 1 and 4 x item 3.
Item 3 x 4 = 3.96 The tax is actually 0.198 but I set just two decimal points. That is why is showing 0.20. This is fine with me. What is NOT fine is the fact that is just taking into consideration the last (second) item and not all (two) items. The correct tax amount whould be .34 which is 0.05 * (2.90 1º item + 3.96 2º item). But is just considering the 3.96 2º and last item. That is why the tax is coming .20, because .05*3.96 = .198 = .20

No, it's +=

Your goal is to print out the tax at the end, which is:
2.9 + 3.96 = 6.86

.05 * 6.68 = .343

I think the real problem now that I think about it is that you did not initialize the tax to 0

double tax;

should be:
double tax=0;

(I had fixed this in my version of your code here but forgot to mention it previously)

Also, don't forget to write out the total bill at the end!

THANKS A LOT. I REALLY APPRECIATE !!!
You are right about the += and the problem was that I did not initializa the variable tax to 0.
T H A N K S !!!!!!

This article has been dead for over six months. Start a new discussion instead.