Can you help me code this problem by using simple if-else statements? thank you!
Problem: A 25m Race Track is divided into 5m of Regular Soil, 4m of Rubberized Floor, 7m of Mud and 9m of Asphalt. Create a program that will accept the distance covered in meters from the starting line and outputs which part of the Race Track they will land.
Ex:
If input is 2m, they will land on Regular Soil.
If input is 8m, they will land on Rubberized Floor.
If input is 19m, they will land on Asphalt.
If input is 27m, they will land on Regular Soil
here is my code:
#include<iostream>
using namespace std;
I got the impression from the example that the racers can do multiple laps. Therefore, the line 8 is required.
However, it had logical error. You set the meters_covered to 5. That is not want you want. You want to deduct all full laps from the distance. The operator% is the correct tool, but the divisor has to be the lenght of the lap, not 10.
Edit: While the if..else chain is trivial and good practice for a starter, it is not the only approach. For example, this one chooses text from a "table":