Click here to Skip to main content
15,305,577 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to make these three functions in my code:

1: readOption function (return a valid option). You must validate the option to make
sure the user enters a valid option.

2: userInput function that takes reference parameters to read clubType (Sports or
Ultra Sports), number of months, and number of personal training sessions. This
must be a void function. You are required to use reference parameters.

3: calcCost function that takes the clubType, number of months, and number of
personal training sessions, calculates and displays the cost to the user. This is a
void function.

What I have tried:

Here is my code:

/*******************************************************************************
** Program Name: Gym Membership
** File Name: file a03.cpp
** Assignment: 03
********************************************************************************/

#include <iostream>
using namespace std;
void welcomeMessage();
void Menu();
char readOption(char userChoice);
int main()
{
	char userChoice;
	welcomeMessage();
	cout<<readOption(userChoice);
	
}
void welcomeMessage()
{	
	//Display Information 
	
	cout << "Welcome to my fitClub program!!" << endl;
	cout << "\nThe cost to become a member of the fitClub center is as follows:" << endl;
	cout << "\nThe membership fee per month for Sports Club is $20.00" << endl;
	cout << "The membership fee per month for Ultra Sports Club is $30.00" << endl;
	cout << "If the membership is bought and paid for 12 or more months, the discount is 10% off membershipcost" << endl;
	cout << "Personal training sessions are $10.00 per session" << endl;
	cout << "If more than five personal training sessions are bought and paid for, the discount on each session is 20%" << endl;
}

void Menu()					//Print Menu
{
	cout << "\nPlease pick one of the following options:" << endl;
	cout << "(C/c) Calculate membership costs." << endl;
	cout << "(Q/q) quit this program." << endl;
}
char readOption(char userChoice)
{
	bool contiLoop = true;
	while (contiLoop)		//While loop start if condition is true
	{
		Menu();
		cin >> userChoice;
 	switch (userChoice)
		{
			case 'c':				//case for small and case-sensitive alphabet
			case 'C':
				{
					char clubType;
					int monthsOfMembership;
					int personalTrainings;
					double amount = 0.0;
					double pamount = 0.0;
					bool loop = true;
					while (loop)			//Nested while loop for condition
					{
						cout <<"\nWould you prefer (S)ports or (U)ltra Sports Club:";
						cin >> clubType;
						//cout << clubType;
						if (clubType == 'S' || clubType == 'U' || clubType == 's' || clubType == 'u')
						{
							loop = false;
						}
						else
							cout <<"\nInvalid membership type! Please try again!" << endl;
					}

					bool validmonths = true;
					while (validmonths)
					{
						cout << "How many months of membership would you like?" << endl;
						cin >> monthsOfMembership;
						if (monthsOfMembership > 0)
							validmonths = false;
					}

					cout << "How many personal training sessions would you like?" << endl;
					cin >> personalTrainings;
					if (clubType == 'S' || clubType == 's')
					{
						amount += monthsOfMembership *20.0;
					}
					else if (clubType == 'U' || clubType == 'u')
					{
						amount += monthsOfMembership *30.0;
					}

					if (monthsOfMembership >= 12)
					{
						amount = amount - (amount *10 / 100);
					}

					cout << "\nYour membership cost after the 10% off is $" << amount << endl;
					if (personalTrainings > 0 && personalTrainings <= 5)
						pamount += personalTrainings *10.0;
					else if (personalTrainings > 5)
						pamount += personalTrainings *8.0;	// after 20% discount per session is 8$
					cout << "Your personal training cost for " << personalTrainings << " sessions is $ " << pamount << endl;
					cout << "Your total membership cost is $" << amount + pamount << endl;
				}

				break;
			case 'q':
			case 'Q':
				{
					cout << "Thank you for checking out my fitClub center!! Come back and be fit!" << endl;
					contiLoop = false;
				}

				break;
			default:
				{
					cout << "Invalid option!!" << endl;
				}
		}
	}

	return 0;
}
Posted
Updated 14-May-22 8:26am
Comments
Rick York 14-May-22 12:34pm
   
Have a look at the functions toupper and tolower.

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
   
Comments
CPallini 14-May-22 7:03am
   
5.
You have defined welcomeMessage, Menu and readOption. You still need to create userInput and calcCost. Also your readOption function does not return the option, but always returns zero. It also includes much of the code that most likely belongs in one of the other functions. Read the assignment closely again, and follow the instructions.
   
Comments
CPallini 14-May-22 7:03am
   
5.
Richard MacCutchan 14-May-22 8:34am
   
Thanks, more points for pointing out the obvious. :(
The task is there like a recipe. Take the 3 functions with the given parameters...
The main program would then look something like this:
C++
int main()
{
	welcomeMessage();

	for (;;) {
		char useroption = Menu();
		char clubType;

		if (useroption == 'Q') {
			cout << "Thank you for checking out my fitClub center!! Come back and be fit!" << endl;
			break;
		}

		// if (useroption == 'C') 
		// 1: readOption function(return a valid option). You must 
		// validate the option to make sure the user enters a valid 
		//option.
		clubType = readOption();
		
		// 2: userInput function that takes reference parameters to read 
		// clubType  number of months, and number of personal training 
		// sessions. This must be a void function.You are required to use
		// reference parameters.
		int monthsOfMembership, personalTrainings;
		userInput(clubType, monthsOfMembership, personalTrainings);

		// 3: calcCost function that takes the clubType, number of 
		// months, and number of personal training sessions,  calculates
		// and displays the cost to the user.This is a void function.
		calcCost(clubType, monthsOfMembership, personalTrainings);
	}
	return 0;
}

The note that reference parameters should be used is also important here.
The tip to bring the user input to a uniform spelling with toupper has already been given above.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900