0

thanks everyone. it is solved finally. i did something different than both of you mentioned but it is working.

#include <iostream>
using namespace std;

int main()
{

	// Identifying Variables

	
	int sum=0;
	int count=0;
	int average=0; 
	int smallestnumber=0;
	int largestnumber=0;
	int x=0;

		while(x!=-999)
		{
		cout <<" Enter a number (-999 to quit)";
		cin >> x;
		if (x==-999){
		break;
		}
		sum=sum + x;
		if (count==0){
		largestnumber = x;
		smallestnumber = x;
		}
		if (x > largestnumber){
		largestnumber = x;
		}
		if (x < smallestnumber){
		smallestnumber = x;
		}
		
		count++;

		}

	cout << "The sum of the values entereed is" << sum << endl;
	cout << "The number of values entered is" << count << endl;
	average = sum/count;
	cout << "The average of values entered is" << average << endl;
	cout << "The maximum value entered is" << largestnumber << endl;
	cout << "The minimum value entered is" << smallestnumber << endl;

	
	return 0;

}
0

I suggest this change.

sum += x;
		if (count==0){
		    largestnumber = x;
                    smallestnumber = x;
		}
                else{
                    largestnumber = max( x, largestnumber );
                    smallestnumber = min( x, smallestnumber );
                }

1. Use the += operator. It's just nice.
2 . You should you an if else statement. There's no reason to compare x to largest and smallest if count == 0.
3. I like to use the M = max( x, M ) synatax. It looks much cleaner and reads very easily.

Edited by dusktreader: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.