Loop homework help

closed account (9Nh5Djzh)
Hi everyone!
I need help with an assignment for school. This is the problem:
You are tracking the prices of some asset over time. The user will input a series of floating-point prices (e.g. 16.105 for sixteen dollars, ten and a half cents). When the user enters the price 0 (zero), output the overall minimum, mean, and maximum prices. Hint: there could be thousands or millions of prices to process, so do not try to store each one as it arrives, but keep a running total..

I've been using a while loop for user input, but I don't know how to get the last 0 that marks the end of the list to not be included in calculating the average. Can anyone shine some light on this for me?
Much thanks!
Couldn't you just use an if statement?
closed account (9Nh5Djzh)
I don't know how to do that yet...
Oh don't worry they're not that hard.

Example of one:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

#include<iostream>

using namespace std;

int main()
 {
      int a;
      cin >> a;
     if (a <= 100)
     {
        cout << "You picked a number less than 100" << endl;
     }
   
    if (a >= 100)
    {
       cout << "You picked a number greater than 100" << endl;
    }
      return 0;
  }
 


So you could use an if statement for when your variable is 0.
Last edited on
closed account (9Nh5Djzh)
oh wow, thanks!
I just meant I don't know how to make it so that if the user enters a 0 to finish the line of input using an if statement.
Topic archived. No new replies allowed.