loop and values

Hi. My question is how do i find the highest and lowest entered price? I have to get the result in '.txt' file. I already get all the prices writen there but how do i make it write the highet and lowest prices entered into the '.txt' file? does it require loop in loop?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 #include<iostream>
#include<fstream>>
using namespace std;

int main(){
    float x;
    ofstream fr("results.txt");

    cout<<"Price of first product?"<<endl;
    cin>>x;
    fr<<"all the prices:"<<x<<endl;
while(x!=0){


    cout<<"enter the price of another product or 0 to quit"<<endl;
    cin>>x;
fr<<x<<endl;

}

fr.close();
  return 0;
does it require loop in loop?

No.

The traditional way to do this is to enter the prices into an array, then scan the array for highest and lowest. That can be done with two separate loops. One to enter the values, then one to scan for high and low values.
Or just check each value after it has been entered (after line 16). No array, no extra loop needed.
Topic archived. No new replies allowed.