ending loop

i am trying to make so when the user types in the letter 's' the program starts over from the top of the first loop



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
#include <iostream>
using namespace std;


  
int main()
{
int Divider = 0;
double Value = 0;
double Total = 0;
double Average = 0;
char StartOver = 'y';
bool Running = true;
bool Averaging = true;

     while(Running)
     {
     system("CLS");

     cout << " Welcome to the Average finder " << endl; 

     cout << " if you would like to start over at any time press s " << endl;
     Averaging = true;
      Divider = 0;
      Value = 0;
     Total = 0;
     Average = 0;


          while(Averaging)
          {
                 cout << " Type in a Number: ";
                 cin  >> Value;
                 Divider++;
                 Total += Value;
                 Average = Total/Divider;
                 cout << " the average is: " << Average << endl;
              
                 if (Value == 's')
                 {
                        Averaging = false;
                 }
                 
                

          }
     }
       system ("PAUSE");
       return 0;
}
Last edited on
after"Averaging = false" you should refresh the Total
thank you for that i will fix that but the real problem is that when i
type 's'
to exit loop the loop displays the massage
1
2
  Type in a Number: 
 the average is: 




over and over again
Last edited on
You cannot input the character 's' and store it in a variable of type double, which Value is.

what you can do is change your cin >> Value to a character array.
1
2
 char input[10];
cin >> input; 

then convert the input to Value like this:
Value=atoi(input);
That solves THAT problem, but your program still doesn't seem to find averages.
Last edited on
thanks i got it
Topic archived. No new replies allowed.