# how do i get the largest, smallest, first and last values??

Show 80 post(s) from this thread on one page
Page 2 of 2 First 12
• 03-23-2003
Nikisha
ok so i worked the count thing out..but i still need help with the finding the lowest value
heres my program:

Code:

```#include <iostream> #include <iomanip> using namespace std; int main() {         int n, sum, num, last, count, first, high, low;         float avg;                 sum = 0;         n = 1;         for (int i = 0; i < n; i++)         {                 cout << "Enter an integer: ";                 cin >> num;                 ++n;                 if (num <= 0)                 {                         break;                 }                 sum = sum + num;                 if (i == 0)                 {                         first = num;                 }                         if (high < num)                 {                         high = num;                 }                 if (low > num)                 {                         low = num;                 }         }                 cout << endl;         last = num;                count = n - 1;         avg = sum / count;         cout << "The first number is " << first << endl;         cout << endl;         cout << "The last number is " << last << endl;         cout << endl;         cout << "The highest number is " << high << endl;         cout << endl;         cout << "The lowest number is " << low << endl;         cout << endl;         cout << "Your count of entries was " << count << endl;         cout << endl;         cout << "Sum of integers = " << sum << endl;         cout << endl;         cout << showpoint << fixed;         cout << "Average = " << setprecision(1) << avg << endl;         cout << endl;         return 0; }```
• 03-23-2003
Hammer
When you get the first int, do something like this (as I suggested earlier):

>highest = lowest = last = first = num;

It set all the variables to the value of num. You can of course do that across multiple lines of code, with individual assignments, if you want.

Why are you incrementing n inside the loop? The i variable will always be less than n if you increment them together.
• 03-23-2003
Nikisha
thnx soooo much!!!:D

i tried it n now my program works perfectly!!!!
Show 80 post(s) from this thread on one page
Page 2 of 2 First 12