Question: modify your working Go programs from Assignment #3 in the following ways: (1) The Triathlon Problem Ask the user for the number of triathletes Have
modify your working Go programs from Assignment #3 in the following ways:
(1) The Triathlon Problem
- Ask the user for the number of triathletes
- Have your program loop the inputs, calculations, and outputs for each triathlete
- Use the Printf function to format your output
- The spacing and formatting precision should exactly mirror that as shown below:
How many triathletes are there? 3
Athlete #1:
Enter cycling hours: 2
Enter running hours: 2
Enter swimming hours: 2
Total calories: XXXX
Pounds lost: Y.YY
Athlete #2:
Enter cycling hours: 3
Enter running hours: 2
Enter swimming hours: 4
Total calories: XXXX
Pounds lost: Y.YY
Athlete #3:
Enter cycling hours: 1.7
Enter running hours: 2.11
Enter swimming hours: 1.89
Total calories: XXXX
Pounds lost: Y.YY
Program so far:
package main
import ( "fmt" )
func main() { //variables for the calories and the hours var caloriesCycling int var caloriesRunning int var caloriesSwimming int var hoursCycling int var hoursRunning int var hoursSwimming int var totalCalories int fmt.Println("Welcome to Triathlon Calculator") fmt.Println("Enter the Hours spent in:")// user input follows fmt.Println("Cycling:") //take cycling hours from the user fmt.Scanf("%d ", &hoursCycling)// user input fmt.Println("Running:") //take running hours from the user fmt.Scanf("%d ", &hoursRunning)// user input fmt.Println("Swimming:") //take swimming hours from the user fmt.Scanf("%d ", &hoursSwimming) //Calculate teh calories for cycling, running and swimming caloriesCycling=225*hoursCycling caloriesRunning=225*hoursRunning caloriesSwimming=225*hoursSwimming //print the calories burned in cycling, running and swimming fmt.Println("Calories Burned In Cycling :",caloriesCycling) fmt.Println("Calories Burned In Running :",caloriesRunning) fmt.Println("Calories Burned In Swimming :",caloriesSwimming) //calculate total calories by adding cycling, running and swimming calories totalCalories=caloriesCycling+caloriesRunning+caloriesSwimming fmt.Println("Total Calories Burned :",totalCalories) //print pouds worked off 1 pound need 3800 calories fmt.Println("Pounds worked off :",totalCalories/3800) }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
