Critical Thinking Problem (Lets see if any of you guys can figure it out)

Paradox1

Fully Optimized
Messages
2,913
You need to

Ok. I have to write a code that finds the Largest and smallest integer entered. I do this by checking if the number is greaterthan or less than the other numbers that were entered.. But you theres nothing to compare it to if it keeps changing everytime it loops, I need to make input = something different each time it loops or something then compare the results afterwards but you cant change it during the loop either...

This is pissing me off because if i wasnt so tired id be able to do this in 2 seconds, but im like having a brainfart or something. Like those times when theres a name, or a word or something and its like right at the tip of your tongue you just cant quite get it, only worse

This is what I have so far:

Code:
#include <iostream.h>

	int input, totalint, average, largest, smallest, difls, sum, devideby;

int main()
{
	cout << "Please enter in your integers one at a time. \n(Type 0 to quit)\n";

	do {
		cin >> input;
		totalint = totalint++; 
		sum = sum + input;
					    //If statement goes here

	} while (input !=0);
		devideby = totalint - 1;
		average = sum / devideby;
		cout << "Number of Integers entered: " << totalint - 1<< endl;
		cout << "Average of Combined Integers: " << average << endl;
		cout << "Largest Integer Entered: " << largest << endl;
		cout << "Smallest Integer Entered: " << smallest << endl;
		cout << "Difference Between Largest and Smallest integers: " << difls << endl;
		cout << "Sum of Combined Integers: " << sum << endl;
	return 0;
}

(Project Requirements:
Display number of integers entered
The average of all the integers
Largest integer entered
Smallest integer entered
Difference between largest and smallest integers
)

Ever if you dont get the code part you should be able to get the how to figure out largest and smallest integers (hopefully)
 
You need to implement a dynamic array to store the values that are being entered so you can compare them. Or you can just use a regular array if you know how many numbers you are inputting for comparison before run-time. Let me know if you need more help.
 
I know how this could be done, but I'm in a lecture right now :D

I'll hack it together later for you.
 
Back
Top Bottom