In: Computer Science
You are writing a small program that records a swimmers swim time for a 100 Free Style event, compares it to the best time, and displays back if swimmer improved or added time. The swim time is entered in seconds. Prompt user to enter their best time before an event and current swim time and then display message if user improved or added time and by how many seconds. It's c++ program and use iostream header.
CODE:
#include<iostream>
using namespace std;
//main method
int main(){
float bestTime;
float currentTime;
float changeTime;
//asking the user to enter the best time
cout<<"Enter the swimmer's best swim time in seconds:
";
cin>>bestTime;
//asking the user to enter the current time
cout<<"Enter the swimmer's current swim time in seconds:
";
cin>>currentTime;
//calculating the change in time
changeTime = currentTime - bestTime;
//if the change in time was positive the swimmer added
time
if(changeTime > 0){
cout<<"\nThe user added time: "<<changeTime<<"
seconds"<<endl;
}else if(changeTime < 0){
//if the changeTime is negative the user improved time
cout<<"\nThe user improved time: "<<changeTime<<"
seconds"<<endl;
}else if(changeTime == 0){
//if the change time is 0 the user maintained time
cout<<"\nThe user maintained time"<<endl;
}
return 0;
}
______________________________________________
CODE IMAGES:
____________________________________________
OUTPUT:
_____________________________________________
Feel free to ask any questions in the comments section
Thank You!