So i have to read in a list of rocket names and masses and print them out the rocket names and masses in the reverse order they were entered. The list is terminated by the value "END". However, "END" should not be part of the list and should not be printed out. Max number of rockets is 50. Where do I go from here?
Code:
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
// Main Program
int main( )
{
// Constant Declarations
// Variable Declarations
string r_names [50];
double mass[50];
int i;
string junk;
for(i = 0; i < 49; i++)
{
cout << "Enter a rocket name (END to end list): ";
getline(cin, r_names[i]);
if(r_names[i] != "END")
{
cout << "What is the mass of a " << r_names[i] << ": ";
cin >> mass[i];
getline(cin, junk);
}
if(r_names[i] == "END")
{
break;
}
}
cout << "The rocket's entered in reverse order are:"
<< r_names[i] << setiosflags(ios::fixed) << setw(6)
<< mass[i] << endl;
cout << "\n\nEnd Program.\n";
return 0;
}