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;
char athleteCategory;
float cashBonus;
cout << "Enter amount: ";
cin >> amount;
cout << "Enter Athlete Category: ";
cin>>athleteCategory;
switch(athleteCategory){
case 'G':
cashBonus=amount*0.15;
break;
case 'S':
cashBonus=amount*0.12;
break;
case 'B':
cashBonus=amount*0.1;
break;
case 'P':
cashBonus=amount*0.05;
break;
default:
break;
}
amount+=cashBonus;
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;
char athleteCategory;
float cashBonus;
cout << "Enter amount: ";
cin >> amount;
cout << "Enter Athlete Category: ";
cin>>athleteCategory;
if(amount>0){
if(athleteCategory== 'G'){
cashBonus=amount*0.15;
}
if(athleteCategory== 'S'){
cashBonus=amount*0.12;
}
if(athleteCategory== 'B'){
cashBonus=amount*0.1;
}
if(athleteCategory== 'P'){
cashBonus=amount*0.05;
}
}
amount+=cashBonus;
cout<<"The cash bonus: "<<cashBonus<<"\n";
cout<<"The final amount that is due: "<<amount<<"\n";
system("pause");
return 0;
}

Comments