I need help with this program im working on where you get input from a file and the program checks if the numbers are in ascending order or not and which one is the smallest and largest number in the series..cant use arrays..
This is a my input.txt right now

1 
2 
3 
4 
5

and here is my code so far

#include <fstream>
#include <iostream>

int main( )
{
    using namespace std;
    ifstream in_stream;
    ofstream out_stream;

    in_stream.open("input.txt");
	
	if( in_stream.fail() ){
		cout << "The input file does not exist";
	}

    out_stream.open("output.txt");

	int input, min_store, max_store,store;
	char ans;
    
	in_stream >> input;
	min_store = input;
	max_store = input;

	for ( int i = 0; i < 5; i++){
		in_stream >> store;

		if( store < input ){
			ans = 'n';
		}
        
		if( input > max_store ){
			max_store = input;
		}

		if( store < min_store ){
			min_store = store;
		}

		in_stream >> input;

	}

	if ( ans = 'n' ){
		out_stream << "The numbers are not in ascending order"<< endl;
	}
	else{
		out_stream << "The numbers are in ascending order"<< endl;
	}
    
    out_stream << "The smallest number is "<< min_store<< endl;
	out_stream << "The largest number is "<< max_store<< endl;

	in_stream.close( );
    out_stream.close( );

    return 0;
}

line 13: If that is executed the next line should be exit(1) to prevent further program processing. No point continuing when the input file doesn't exist.

lines 26 and 40: delete both these, only one is needed. See the while loop I posted below for correction.

linet 25: don't use a for-next loop for this but a while statement that just reads the entire file regardless of the number of lines in it. Since your not allowed to use arrays there is no point using any sort of index counter.

while( in_stream >> store )
{
   // blabla
}

The next thing you need to add inside that loop is test if the current value of store is less then the previous value read. If it is less then the file is not in ascending order. You already have part of this on line 28, but what you are missing is to set input = store; after the test on line 28 to get ready for the next loop iteration.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.