-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileLoopFlagControlledDEMO.cpp
More file actions
70 lines (56 loc) · 2.22 KB
/
Copy pathWhileLoopFlagControlledDEMO.cpp
File metadata and controls
70 lines (56 loc) · 2.22 KB
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
//************************************************************************
// Author: Rolando Carreon
// Date: feb 20 2025
// Language: C++
// Assignment: WhileLoopFlagControlledDEMO
// Description: get the number of steps for multiple days, calculate the average
// daily steps and provide the user feedback.
//************************************************************************
#include<iostream>
using namespace std;
int main()
{
// declare local variables //
int stepsPerDay = -1;
int totalSteps = 0;
int dayNumber = 0;
float stepsAverage = 0.0;
bool doAgain = true; // the loop control variable (LCV)
// continue getting daily steps till the user enters 0 , and the
// flag changes to false
while(doAgain)
{
cout << "Enter the steps for day " << dayNumber + 1
<< " or 0 to quit: ";
cin >> stepsPerDay;
// check if the user entered a positive number of steps //
if(stepsPerDay > 0)
{
totalSteps += stepsPerDay;
dayNumber++; // go to the next day
// doAgain = true; unessecary operation
}
else // 0 or less entered by user
doAgain = false; // set the LCV to false
}
//check to make sure the user entered at least on days
// worth of steps, which means dayNumber is 1 or greater
if(dayNumber != 0 )
{
// calculate the average steps
// static cast to a float
stepsAverage = static_cast<float>(totalSteps) / dayNumber;
// display the average steps
cout << "Your daily steps average is " << stepsAverage << endl;
// provide the user feedback based on the average daily steps //
// curly braces not needed if its just one statment
if(stepsAverage >= 7500)
cout << "Great Job - you are getting yout steps in!\n";
else
cout << "Looks like you need to do some more walking!\n";
}
else
cout << "You didn't enter any data.\n";
cout << endl;
return 0;
}