Answer to Question #216280 in C++ for kaydee

Question #216280
The athletics department of a university gives athletes a cash bonus after completing an event as follows:  A bronze medalist gets a 10% cash bonus,  A silver medalist gets a 12% cash bonus and  A gold medalist gets a 15% cash bonus.  All the other athletes get a 5% cash bonus if they are placed among the first 6 athletes. You are requested to write two versions of a program that calculates and displays the final amount that is due, after discount. (i) (ii) Hint: The first version of the program uses a switch statement to implement the above program. The second version of the program uses nested-if statements. Use the following variables: float amount; // the amount that can be divided between the // athletes char athleteCategory;// the medal recieve: 'G' (gold) or // 'S' (silver) or 'B' (bronze) or // 'P'(places) float cashBonus;
1
Expert's answer
2021-07-12T07:17:48-0400
The first version of the program uses a switch statement to implement the above program. 

#include <iostream>
#include <string>


using namespace std;


int main() { 
	float amount; // the amount that can be divided between the athletes 
	char athleteCategory; // the medal recieve: 'G' (gold) or  'S' (silver) or 'B' (bronze) or  'P'(places) 
	float cashBonus; 
	cout << "Enter amount: "; 
	cin >> amount; 
	cout << "Enter Athlete Category: ";
	cin>>athleteCategory;
	
	switch(athleteCategory){
	case 'G':
		//A gold medalist gets a 15% cash bonus. 
		cashBonus=amount*0.15;
		break;
	case 'S':
		//A silver medalist gets a 12% cash bonus and 
		cashBonus=amount*0.12;
		break;
	case 'B':
		//A bronze medalist gets a 10% cash bonus.
		cashBonus=amount*0.1;
		break;
	case 'P':
		//All the other athletes get a 5% cash bonus if they are placed among the first 6 athletes.
		cashBonus=amount*0.05;
		break;
	default:
		break;
	}
	amount+=cashBonus;
	
	//displays the final amount that is due, after discount. 
	cout<<"The cash bonus: "<<cashBonus<<"\n";
	cout<<"The final amount that is due: "<<amount<<"\n";




	system("pause");
	return 0;
}

The second version of the program uses nested-if statements. 

#include <iostream>
#include <string>


using namespace std;


int main() { 
	float amount; // the amount that can be divided between the athletes 
	char athleteCategory; // the medal recieve: 'G' (gold) or  'S' (silver) or 'B' (bronze) or  'P'(places) 
	float cashBonus; 
	cout << "Enter amount: "; 
	cin >> amount; 
	cout << "Enter Athlete Category: ";
	cin>>athleteCategory;


	if(amount>0){
		if(athleteCategory== 'G'){
			//A gold medalist gets a 15% cash bonus. 
			cashBonus=amount*0.15;
		}
		if(athleteCategory== 'S'){
			//A silver medalist gets a 12% cash bonus and 
			cashBonus=amount*0.12;
		}	
		if(athleteCategory== 'B'){
			//A bronze medalist gets a 10% cash bonus.
			cashBonus=amount*0.1;
		}	
		if(athleteCategory== 'P'){
			//All the other athletes get a 5% cash bonus if they are placed among the first 6 athletes.
			cashBonus=amount*0.05;
		}	
	}


	amount+=cashBonus;


	//displays the final amount that is due, after discount. 
	cout<<"The cash bonus: "<<cashBonus<<"\n";
	cout<<"The final amount that is due: "<<amount<<"\n";




	system("pause");
	return 0;
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS