-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileLoopSentinelControlledDEMO.cpp
More file actions
67 lines (52 loc) · 1.92 KB
/
Copy pathWhileLoopSentinelControlledDEMO.cpp
File metadata and controls
67 lines (52 loc) · 1.92 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
//************************************************************************
// Author: Rolando Carreon
// Date: feb 20 2025
// Language: C++
// Assignment: WhileLoopSentinelControlledDEMO
// 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; // the loop control variable (LCV)
float stepsAverage = 0.0;
// get daily steps from the user intiil the user enters 0
//(sentinel value )
while(stepsPerDay != 0)
{
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
}
}
//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;
}