values and loop

Hi ,my question is how do i make this while loop to not count the input '0' as a number. It should only ask you for numbers bigger than '0' and '0' quits the loop, but when i check my .txt file it still shows '0' as an entered number but not as a way to quit the loop. How do i tell this program that '0' is not a choice?? That '0' also shows up in .txt file as the lowest entered number but the number cant be lower or equal to '0'.
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
  #include<iostream>
#include<fstream>
using namespace std;

int main(){
    float x;
    int a=0;
    long int b=100000000000000;
    ofstream fr("results.txt");

    cout<<"first number?"<<endl;
    cin>>x;
    fr<<"all the numbers:"<<x<<endl;
while(x!=0){
if(x>a){
    a=x;
}
if (x<b){

    b=x;
}
    cout<<"another number or 0 to quit"<<endl;
    cin>>x;
fr<<x<<endl;
if(x>a){
        a=x;

    }
    if(x<b){

        b=x;
    }
}
cout<<"biggest number:"<<a;
cout<<"lowest number:"<<b;
fr<<"biggest number:"<<a;
fr<<"lowest number:"<<b;
fr.close();
  return 0;
}
After line 23,add this:
1
2
if(x==0)
  break;

Try this if it works,or else maybe i didnt understand your quesation properly.
The unconventional style of indentation makes the code pretty hard to read.

However, you have some duplicate code inside the while loop.
The closing brace } of the loop should follow immediately after the cin >> x; at line 23.

Then what to do with the rest of the unwanted code (lines 24 to 32)?
Delete almost all of it. The only non-duplicated line is line 24, fr<<x<<endl;
Remove that line, instead insert that piece of code at the start of the loop, just after the opening brace { at line 15.

Almost there. Now you just need to fix line 13 which should simply read
fr << "all the numbers:\n";

or rather i should add:
1
2
if(x<=0) 
   break;
Topic archived. No new replies allowed.