You are here:

# C++/C++ newbie need help with fixing code

Question
Hi:
I’m a C++ newbie and I’m taking my 2nd class but, I’m confused as to how to do my homework problem. I have to use a floating decimal and I have written the script but, it has several errors and I would like some help. Whatever assistance you can give me will be appreciated. I will paste the question and my code here.
Thank You!
Lucy likes to jog in the morning.
As she jogs, she counts the number of strides, she makes during the first minute and then again during the last minute of her jogging.
She then averages these two numbers together and calls this the average the number of strides she makes during a minute.

Write a program that asks for the number of strides made during the first minute and the number of strides made during the last minute (each an integer) and then asks for the  total number of hours and minutes that Lucy jogs. (each an integer)
Assume Lucy’s stride length is 2.5 feet. Using the fact that there are 5280 feet in a mile, have your program display the average number of strides Lucy makes in a minute (a float) and the distance Lucy jogged in miles (a float)

Below is a sample run….your code should work for any input I choose .

What was the number of strides you made during the first minute?
128
What was the number of strides you made during the last minute?
123
How many hours did you jog?
1
How many minutes did you jog?
15
Your average number of strides per minute is: 125.5
The distance you jogged was: 4.46 miles
CODE
#include  <iostream>
using namespace std;

int main()
{
int number_of_feet, feet_per_minutes, feet_per_miles, miles_hour;
float numMinutes, numMiles
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << " What was the number of feet made during the first minute: ";
cin >> numFeet;
cout << " What was the number of feet made during the last minute: ";
cin >> numFeet;
cout << “What is the average number of feet:”;
cin >> “numAvfeet;
cout<<” How many hours jogged:”;
cin >> numHours;
cout << “How many minutes jogged:”;
cin >> numMinutes;
cout << “How many jogged miles per hour:";
cout<< numMiles / numHours << '\n';

return 0;
}

1. First define the two constants that are given:

const float stride_length_in_feet = 2.5 ;
const int number_of_feet_per_mile = 5280 ;

2. Then, accept the other values as input from the user:

cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout << " What was the number of strides made during the first minute: ";
int number_of_strides_first_minute ; cin >> number_of_strides_first_minute ;

cout << " What was the number of strides made during the last minute: ";
int number_of_strides_last_minute ; cin >> number_of_strides_last_minute ;

cout << "How many hours did you jog? " ;
int hours_jogged ; cin >> hours_jogged ;

cout << "How many minutes did you jog? " ;
int minutes_jogged ; cin >> minutes_jogged ;

3, Now, compute the average the number of strides and print it out (note the division by 2.0 and not 2; we do not want integer division):

float average_strides_per_minute =
(number_of_strides_first_minute+number_of_strides_last_minute) / 2.0 ;
cout << "Your average number of strides per minute is: "
<< average_strides_per_minute << '\n' ;

4. Finally, compute the distance in miles and print it out (do it one small step at a time):

int total_minutes =  hours_jogged * 60 + minutes_jogged ;
float total_strides = average_strides_per_minute * total_minutes ;
float total_distance_in_feet = total_strides * stride_length_in_feet ;
float total_distance_in_miles = total_distance_in_feet / number_of_feet_per_mile ;

cout << "The distance you jogged was: " << total_distance_in_miles << " miles.\n" ;

Put that all together and you are done!
Questioner's Rating
 Rating(1-10) Knowledgeability = 10 Clarity of Response = 10 Politeness = 10 Comment Thank You for all of your assistance, you have been very helpful.

C++

Volunteer

#### vijayan

##### Expertise

my primary areas of interest are generic and template metaprogramming, STL, algorithms, design patterns and c++11. i would not answer questions about gui and web programming.