Help with Functions

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
  #include <iostream>
#include <iomanip>
#include <string>

using namespace 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;
      }
	
   else if(power2 > power1 && power2 > power3)
      {
        highestPower = power2;
        pwrOutput = highestPower;
        packNbr = 2;
        jetPacks = packNbr;
       }
    else if(power3 > power1 && power3 > power2)
       {
        highestPower = power3;
        pwrOutput = highestPower;
        packNbr = 3;
        jetPacks = packNbr;
       }
}
Hiya.

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.

-Albatross
What happened here? Yesterday the code looked like this:
1
2
3
4
5
void mostPowerful(double power1, double power2, double power3, double &mostPower, int &packNbr)
{
 // etc.
		
}


and today it looks like this:
1
2
3
4
5
double mostPowerful(double pwrOutput, int jetPacks)
{
  // etc.

}

http://www.cplusplus.com/forum/beginner/114835/#msg627235

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.
Topic archived. No new replies allowed.