Trash number on my menu program

NEED HELP ON THIS: my program shows trash number

#include <iostream>
#include <stdlib.h>

using namespace std;

int main()
{
start:
int sum;
float total[12],choice[13],tier[4];
char mcc,sc,bc,n;
string ordered[12];

mainmenu:
cout << "************************" <<endl;
cout << "GRABE KA BARATO! PRAMIS" <<endl;
cout << "************************" <<endl;
cout << " 1.Main Course" <<endl;
cout << " 2.Snacks" <<endl;
cout << " 3.Beverages" <<endl;
cout << " 4.Time to Pay" <<endl;
cout << "************************" <<endl;
cout << "Enter your choice: ";
cin >> tier[1];
cout <<endl;
system("cls");

ordered[1]="HAM";
ordered[2]="FRIED LUMPIA";
ordered[3]="FRIED CHICKEN";
ordered[4]="GROUND BEEF";
ordered[5]="HOTDOG";
ordered[6]="HAMBURGER";
ordered[7]="BEEF BURGER";
ordered[8]="SANDWICH";
ordered[9]="COKE";
ordered[10]="SPRITE";
ordered[11]="ROYAL";
ordered[12]="MINERAL WATER";

if (tier[1]==1)
{
mc:
cout << "A. Ham**********************P5.00" <<endl;
cout << "B. Fried Lumpia*************P5.00" <<endl;
cout << "C. Fried Chicken************P20.00" <<endl;
cout << "D. Ground Beef**************P10.00" <<endl;
cout << "E. Main Menu" <<endl;
cout << "Enter your Choice: ";
cin >> mcc;

switch(mcc)
{
case 'A':
cout << "How many HAM?: ";
cin >> choice[1];
total[1]=choice[1]*5;
system("cls");
goto mc;
break;
case 'B':
cout << "How many FRIED LUMPIA?: ";
cin >> choice[2];
total[2]=choice[2]*5;
system("cls");
goto mc;
break;
case 'C':
cout << "How many FRIED CHICKEN?: ";
cin >> choice[3];
total[3]=choice[3]*20;
system("cls");
goto mc;
break;
case 'D':
cout << "How many GROUND BEEF?: ";
cin >> choice[4];
total[4]=choice[4]*10;
system("cls");
goto mc;
break;
case 'E':
system("cls");
goto mainmenu;
break;
}
}
else if(tier[1]==2)
{
s:
cout << "A. Hotdog*******************P10.00" <<endl;
cout << "B. Hamburger****************P10.00" <<endl;
cout << "C. Beef Burger**************P12.00" <<endl;
cout << "D. Sandwich*****************P14.00" <<endl;
cout << "E. Main Menu" <<endl;
cout << "Enter your choice: ";
cin >> sc;

switch(sc)
{
case 'A':
cout << "How many HOTDOG?: ";
cin >> choice[5];
total[5]=choice[5]*10;
system("cls");
goto s;
break;
case 'B':
cout << "How many HAMBURGER?: ";
cin >> choice[6];
total[6]=choice[6]*10;
system("cls");
goto s;
break;
case 'C':
cout << "How many BEEF BURGER?: ";
cin >> choice[7];
total[7]=choice[7]*12;
system("cls");
goto s;
break;
case 'D':
cout << "How many SANDWICH?: ";
cin >> choice[8];
total[8]=choice[8]*14;
system("cls");
goto s;
case 'E':
system("cls");
goto mainmenu;
break;
}
}
else if(tier[1]==3)
{
b:
cout << "A. Coke*************************P13.00" <<endl;
cout << "B. Sprite***********************P13.00" <<endl;
cout << "C. Royal************************P13.00" <<endl;
cout << "D. Mineral Water****************P25.00" <<endl;
cout << "E. Main Menu" <<endl;
cout << "Enter your choice: ";
cin >> bc;

switch (bc)
{
case 'A':
cout << "How many COKE?: ";
cin >> choice[9];
total[9]=choice[9]*13;
system("cls");
goto b;
break;
case 'B':
cout << "How many SPRITE?: ";
cin >> choice[10];
total[10]=choice[10]*13;
system("cls");
goto b;
break;
case 'C':
cout << "How many ROYAL?: ";
cin >> choice[11];
total[11]=choice[11]*13;
system("cls");
goto b;
break;
case 'D':
cout << "how many MINERAL WATER?: ";
cin >> choice[12];
total[12]=choice[12]*25;
system("cls");
goto b;
break;
case 'E':
system("cls");
goto mainmenu;
break;
}
}
else if (tier[1]==4)
{
cout << "**********************" <<endl;
cout << "TOTAL:" <<endl;
if (total[1]>0)

cout << total[1] << "\t" << ordered[1] <<endl;

if (total[2]>0)

cout << total[2] << "\t" << ordered[2] <<endl;

if (total[3]>0)

cout << total[3] << "\t" << ordered[3] <<endl;

if (total[4]>0)

cout << total[4] << "\t" << ordered[4] <<endl;

if (total[5]>0)

cout << total[5] << "\t" << ordered[5] <<endl;

if (total[6]>0)

cout << total[6] << "\t" << ordered[6] <<endl;

if (total[7]>0)

cout << total[7] << "\t" << ordered[7] <<endl;

if (total[8]>0)

cout << total[8] << "\t" << ordered[8] <<endl;

if (total[9]>0)

cout << total[9] << "\t" << ordered[9] <<endl;

if (total[10]>0)

cout << total[10] << "\t" << ordered[10] <<endl;

if (total[11]>0)

cout << total[11] << "\t" << ordered[11] <<endl;

if (total[12]>0)

cout << total[12] << "\t" << ordered[12] <<endl;


total[0]=total[1]+total[2]+total[3]+total[4]+total[5]+total[6]+total[7]+total[8]+total[9]+total[10]+total[11]+total[12];
cout << total[0] <<endl;
cout << "**********************" <<endl;
cout << "New Order?(Y/N): ";
cin >> n;
if (n=='Y')
{
system("cls");
goto start;
}
else if(n=='N')
{
exit(0);

}


}
}
Please edit your code so it's between code tags - http://www.cplusplus.com/articles/jEywvCM9/

Your code is messed up. You're using goto which you should not, learn how to use loops instead.

The problem you are having is with your array.

string ordered[12];

When you create an array of 12 elements. You access them via the indexes 0-11. Not 1-12.


ordered[12]="MINERAL WATER";

This doesn't work. ordered[12] doesnt exist. You want ordered[11]. And the ordered[1]="HAM"; should start at 0, not 1. Same with tier[4]
Topic archived. No new replies allowed.