-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileLoopCounterControlledDEMO.cpp
More file actions
62 lines (45 loc) · 1.83 KB
/
Copy pathWhileLoopCounterControlledDEMO.cpp
File metadata and controls
62 lines (45 loc) · 1.83 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
//************************************************************************
// Author: Rolando Carreon
// Date: feb 18 2025
// Language: C++
// Assignment: WhileLoopCounterControlledDEMO
// Description: get the number of steps for 5 days, calculate the average
// daily steps and provide the user feedback.
//************************************************************************
#include<iostream>
using namespace std;
int main()
{
// declare local variables //
int stepsPerDay = 0;
int totalSteps = 0;
int dayNumber = 1; // the loop control variable (LCV)
float stepsAverage = 0.0;
// loop through 5 days getting the number of steps, totaling the steps
while (dayNumber <= 5)
{
cout << "Enter the steps for day " << dayNumber << ": ";
cin >> stepsPerDay;
// add the steps to the total //
totalSteps += stepsPerDay;
// increment the dayNumber - LCV (LoopControlVariable)
dayNumber++;
}
// calculate the average steps
// add .0 to convert int to floats, u could static cast but this is more readable
stepsAverage = totalSteps / 5.0;
// 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";
cout << endl;
// line 44-47 rewitten as a turnary operator //
// cout << ( (stepsAverage >= 7500) ?
// "Great Job - you are getting yout steps in!\n" : // true
// "Looks like you need to do some more walking!\n" ); // false
return 0;
}