Suppose that sale and bonus are double variables. Write an if...else
statement that assigns a value to bonus as follows: If sale is greater
than $20,000, the value assigned to bonus is 0.10, that is 10%; If sale
is greater than $10,000 and less than or equal to $20,000, the value
assigned to bonus is 0.05, that is 5%; otherwise the value assigned to
bonus is 0, that is 0%.
#include <iostream>
#include <string>
using namespace std;
void main(){
double sale, bonus;
cout<<"Enter sale: ";
cin>>sale;
//if sale is greater than $20,000, the value assigned to bonus is 0.10, that is 10%;
if(sale>20000){
bonus=sale*0.10;
}
//If sale is greater than $10,000 and less than or equal to $20,000,
//the value assigned to bonus is 0.05, that is 5%;
else if(sale>10000 && sale<=20000){
bonus=sale*0.05;
}
//otherwise the value assigned to bonus is 0, that is 0%.
else{
bonus=0;
}
cout<<"Bonus = "<<bonus<<"\n\n";
cin>>sale;
}
Comments
Leave a comment