Been working at this assignment for a while and it seems like I've hit a brick wall. Not sure why this assignment is giving me so many problems. Could someone look at my code and help? This is one part of the overall program and I think once I get this one done the other functions won't be as troublesome.
Also, should my menu function make all the calls to the other functions dependent upon the character (Letter)entered and execute the statements within that function or the main? This is a bit confusing and hard to understand when there are so many other competing classes. Thanks in advance for the assistance.
#include <iostream>
#include <iomanip>
#include <string>
usingnamespace std;
//Function Prototypes
double mostPowerful(double pwrOutput, int jetPacks);
char menu();
int main()
{
double power1, power2, power3; //variable to hold user power input
double highestPower = 0; //variable to hold largest power input
int packNbr; //variable to hold pack number associated with most power
char userChoice = ' '; //variable to hold character literal
char userChoice = menu(); //call to menu function returning a character
while (userChoice != 'Q')
{
cout<<"Please enter the option (M, D, H, or Q: ";
cin>>userChoice;
if(userChoice == 'M')
{
cout<<"Enter 3 power-output measurements in MW: "<<endl;
cin>>power1>>power2>>power3;
//function call to the most powerful function
mostPowerful(double pwrOutput, int jetPacks);
cout<<"The largest power output is: "<<highestPower<<"and the
Jetpack number is: "<<packNbr<<endl;
}
}//end while loop for now (will have to call two additional functions later.
system("Pause");
return 0;
}
//Function Definitions
//Define call to menu selection first
char menu()
{
char userChoice;
cout<<"Welcome to Joe Snuffy's Spaceship Company"<<endl;
cout<<"(M)"<<"ost Powerful Calculation"<<endl;
cout<<"(D)"<<"iscount Calculation"<<endl;
cout<<"(H)"<<"ow Many Calculation"<<endl;
cout<<"(Q)"<<"uit"<<endl;
cout<<"Please Enter the option (M, D, H, or Q): "<<endl;
cin>>userChoice;//user's input choice
return userChoice;//return user choice
}
//Function definition for mostPowerful function
double mostPowerful(double pwrOutput, int jetPacks)
{
if(power1 > power2 && power1 > power3)
{
highestPower = power1;
pwrOutput = highestPower;
packNbr = 1;
jetPacks = packNbr;
}
elseif(power2 > power1 && power2 > power3)
{
highestPower = power2;
pwrOutput = highestPower;
packNbr = 2;
jetPacks = packNbr;
}
elseif(power3 > power1 && power3 > power2)
{
highestPower = power3;
pwrOutput = highestPower;
packNbr = 3;
jetPacks = packNbr;
}
}
mostPowerful won't be able to look at the values of power1, highestPower, pwrOutput, and all the other variables in main that mostPowerful tries to use simply because they're in main and not in mostPowerful. You need to send those into the function as arguments as well.
Do you remember how to call a function that takes arguments? You don't need to restate the types of the arguments that you're using (I'm specifically looking at line 28).
One more thing. Did you cover references yet? If so, you might find them useful.
I'm just curious as to what was the motivation for throwing out code which (a) worked and (b) conformed to the requirements of the question and replacing it with code which does neither?
Sorry, I was trying everything I could to get the code to actually prompt me for input, then make the comparisons and finally output my intended results. I removed most of it because I had been working on it roughly for 6+ hours using the book and C++ for dummies to help. Do you think I was on the right path with the original code? I'm going to work on this tomorrow and will post again if I get stuck again which is most likely. Thanks to everyone that has the ability to teach a very complex skill.