Statement not appearing at the right place
Aug 25, 2014 at 2:38am UTC
Hi I have an issue with my codes as according to what I created the fitness level have to appear right after I enter the time take to 3 miles. However it only appears once after repeating five times.
My codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
struct fitnessProfile
{
string name;
int age;
double time;
};
void get_data(fitnessProfile & the_data);
//Postcondition: the_data.age and the_data.time have been given values that the user entered at the keyboard.
fitnessProfile myProfile;
int main()
{
fitnessProfile myProfile;
get_data(myProfile);
double fitness;
fitness = myProfile.time;
if (fitness < 36)
{
cout <<"Your fitness is on Level 5!" ;
}
else if (fitness <40)
{
cout <<"Your fitness is on Level 4!" ;
}
else if (fitness <44)
{
cout <<"Your fitness is on Level 3!" ;
}
else if (fitness <48)
{
cout <<"Your fitness is on Level 2!" ;
}
else
{
cout << "Your fitness is on Level 1!" ;
}
}
void get_data(fitnessProfile & the_data)
{
int x;
x =0 ;
while (x <5)
{
cout<<"Profile number: " <<x+1<<endl;
cout << "Enter your name: " ;
cin >> the_data.name;
cout << "Enter your age: " ;
cin >> the_data.age;
cout << "Please enter time taken to walk 3 miles (mins): " ;
cin >> myProfile.time;
x=x+1;
}
cin.ignore();
cin.ignore();
}
Aug 25, 2014 at 3:29am UTC
What's the point of line 59?
Aug 25, 2014 at 3:32am UTC
Line 59 is to create a loop to repeat the statements five times.
Aug 25, 2014 at 3:34am UTC
Why would you want to do that?
Aug 25, 2014 at 3:41am UTC
Based on the question it requires to have five people's profile there I needed to create the loop to hold five records
Aug 25, 2014 at 3:49am UTC
But you don't have any place to store 5 entries. You just have the one the_data.
Aug 25, 2014 at 3:53am UTC
What must I do in order to have place to store five entries
Topic archived. No new replies allowed.