Hi, i need help reversing an integers while using an array.the code is already complete i just need to reverse the output. Please help me thank you. i have some ideas that i'm working on right now, but comment anyway, thank you so much!!
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <string>
usingnamespace std;
// Character Declarations
char Y; // to rerun the program
// Constaints
constint Capacity = 50;
// Function Declarations
void fillArray(string[], double[], int&);
void printArray(string[], double[], int);
int main()
{
// Output Identification
system("CLS");
cout << "In-class #11 by Christopher Adique -\n "
<< "Reverse Rocket Order\n\n";
double newMass[Capacity]; // array for mass
string newName[Capacity]; // array for names
int numOfElements = 0; // number of elements
do{
fillArray(newName,newMass,numOfElements);
printArray(newName, newMass, numOfElements);
cout << "\n\nWould you like to run the program again (Y=Yes) => ";
cin >> Y;
}
while (Y == 'Y' || Y == 'y');
cout << "\n\nEnd Program.\n";
return 0;
}
void fillArray(string newName[], double newMass[], int& numOfElements){
int i = 0; // inital value for i
double mass; // input mass
std::string name; // input name
std::string junk; // clear out name
while ((name != "END") && (i < Capacity)){
cout << "\nEnter a rocket name (END to end list): ";
std::getline (std::cin,name);
newName[i] = name;
if (name != "END"){
cout << "\nWhat is the mass of " << name << ": ";
cin >> mass;
newMass[i] = mass;
std::getline (std::cin,junk);
}
numOfElements++;
i++;
}
}
void printArray(string newName[], double newMass[], int numOfElements){
cout << "\nThe rockets entered in reverse order are: \n";
for (int i = (numOfElements - 2); i >= 0; i--) {
cout << left << setw(25) << newName[i] << setw(10) << right << newMass[i] << endl;
}
}
nvm i got it already, thank you, instead of the counter that you said to put in the bit of code you showed me, i had to put the "nums" and vualla!! HAHA thank you so much though!