Hello guys, I'm brushing back up on C++ it's been a long semester of Assembly Language. Anywho, I am writing a program that keeps track of my grades and can average them up if I need and do many other things. I'm using a switch statement as my menu select. I was wondering if you guys can help. The switch doesn't seem to be working at all.

/*************************************************************************************************

This is a program I'm writing to calculate test grades and weight in certain tests.

**************************************************************************************************/

#include <iostream>
using namespace std;
int OptionMenu(int);
void GradeAve(float GA_number, float G_ave,float GA_sum, int GA_count);
int main()
{   float GA_sum;
    float GA_ave;
	int menunumber=0;
	int GA_count=0;
	float GA_number=0;
 
    OptionMenu(menunumber);
	system("cls");

	   
	switch(menunumber)
	{
            case 1: 
			//GradeAve(GA_number,GA_sum,GA_ave,GA_count);
				cout<<"I hope this works!"<<endl;
			break;

			case 2:
				cout<<"help!"<<endl;
			
			default:
				cout<<"fixed it"<<endl;
	}

system("pause");
return 0;
	    
}

	int OptionMenu(int menunumber)
	{

		cout<<"Choose an option:\n\n1.) Compute grade average.\n\n2.) Calculate a specific tests weight in your final grade.\n\n3.) Store a test grade.\n\n4.) Store a homework grade.\n\n5.) Store a lab assignment grade."<<endl;
	    cin>> menunumber;

		return menunumber;
	}

	void GradeAve(float GA_number, float G_ave,float GA_sum, int GA_count)
	{
		cout<<"How many grades would you like to process?"<<endl;
		cin>>GA_count;

		for(int i = 0;i<GA_count;i++)
		{
			cout<<"Enter a grade:"<<endl;
			cin>>GA_number;
			GA_sum += GA_number;

		}

		G_ave = GA_sum/GA_count;

		return;
	}

Essentially I'm having the user select an option and returning the value to main. from there switch should pick the value up and select the corresponding menu option. Please help. Thanks!

Recommended Answers

All 3 Replies

Code Tags :

/*************************************************************************************************

This is a program I'm writing to calculate test grades and weight in certain tests.

**************************************************************************************************/

#include <iostream>
using namespace std;
int OptionMenu(int);
void GradeAve(float GA_number, float G_ave,float GA_sum, int GA_count);
int main()
{ float GA_sum;
float GA_ave;
int menunumber=0;
int GA_count=0;
float GA_number=0;

OptionMenu(menunumber);
system("cls");


switch(menunumber)
{
case 1: 
//GradeAve(GA_number,GA_sum,GA_ave,GA_count);
cout<<"I hope this works!"<<endl;
break;

case 2:
cout<<"help!"<<endl;

default:
cout<<"fixed it"<<endl;
}

system("pause");
return 0;

}

int OptionMenu(int menunumber)
{

cout<<"Choose an option:\n\n1.) Compute grade average.\n\n2.) Calculate a specific tests weight in your final grade.\n\n3.) Store a test grade.\n\n4.) Store a homework grade.\n\n5.) Store a lab assignment grade."<<endl;
cin>> menunumber;

return menunumber;
}

void GradeAve(float GA_number, float G_ave,float GA_sum, int GA_count)
{
cout<<"How many grades would you like to process?"<<endl;
cin>>GA_count;

for(int i = 0;i<GA_count;i++)
{
cout<<"Enter a grade:"<<endl;
cin>>GA_number;
GA_sum += GA_number;

}

G_ave = GA_sum/GA_count;

return;
}

>>int OptionMenu(int);

Since that function is returning the option selected there is no need to pass any parameters to it. Then in main() just write menunumber = OpenMenu();

Just by looking at your prototype and what you do with the function
call tells me that this :

int OptionMenu(int);

should be pass by reference.

int OptionMenu(int&);

Or checking again you could do this :

menunumber =  OptionMenu(menunumber);
//instead of 
//OptionMenu(menunumber);

Thats because you need to save the value into menunumber, by
either making it pass by reference or making it equal to its return value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.