Hey guys, I am new to the forum and have a question on my program. The instructions say to write a program that will calculate how much a person would weigh on other planets in our solar system by multiplying their weight by the relative gravity of the chosen planet. I must use a string for the name and planets variable. I am supposed to use parallel arrays to search for the name of the planet entered by the user and find the corresponding relative gravity for that planet from the second array. I also need to use a case structure to allow unique console output statements. This is what I have so far, and when I run the code I get the “Error!” Message. Help would be much appreciated, thanks.
while (weight != -1)
{
for (int x = 0; x < 8; x++)
{
if (planet == planets[x])
{
weight = weight * gravity[x];
//begin switch
switch (x)
{
case 0:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 1:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 2:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 3:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 4:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 5:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 6:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
case 7:
cout << name << " on planet " << planets[x] << " would be " << weight << endl;
break;
default:
cout << " Error! " << endl;
}//end switch
}//end if
}//end for
//ask for additional weights
cout << "Enter your weight: " << endl;
cin >> weight;
cout << "What planet to be weighed on?:(STOP to exit) " << endl;
cin >> planet;
//capitalize planet
transform(planet.begin(), planet.end(), planet.begin(), toupper);
}//end while
}//end while
system("pause");
return 0;
}//end of main