C++ question- "Write a program that will calculate total savings by a student with his/her parents’ contribution. The student’s parents have agreed to add to the student’s savings based the percentage the student saved using the schedule given below" This is the if/else if I used to find out the parents contribution. I now have to make this program again except with a switch statement. I don't know exactly how to do that. The user inputs total earnings, and amount he decided to put away. (My course just started so I have to use very simple processes to do this thank you) Here's the first version:
percent_saved = money_saved / money_earned; // calculates the percent of how much was saved
if (percent_saved <.05) // this if/else if statement assigns the parents percentage of contribution to their students saving
{
parents = .01;
}
else if (percent_saved >= .05 && percent_saved < .1)
{
parents = .025;
}
else if (percent_saved >= .1 && percent_saved < .15)
{
parents = .08;
}
else if (percent_saved >= .15 && percent_saved < .25)
{
parents = .125;
}
else if (percent_saved >= .25 && percent_saved < .35)
{
parents = .15;
}
else
{
parents = .2;
}
parentsmoney = parents*money_earned; // using the correct percentage, this creates the amount of money parents will contribute
total_savings = parentsmoney + money_saved; // this adds together the parent's contribution and the student's savings