Okay, so I am making a program that accepts user input of integers. As you can see I am using an array and i need to get the greatest number, and smallest, range, mean, etc. But I successfully did this for the greatest and figured not much would need to be changed but everything I've tried has given me errors of like -8732113 as the smallest. If needed i can post the code with the greatest included, I took it out so i could just focus on this.
Code:
#include <iostream>
#include <conio.h>
using namespace std;
void main()
{
int nums[50];
int howmany=0;
int largest;
int smallest;
int x;
while(cin >> x)
{
nums[howmany] = x;
howmany++;
}
smallest = nums[0];
for (int s=50; s >= howmany; s--)
{
if(nums[s] <= smallest)
smallest = nums[s];
}
cout << howmany << "\n\n";
cout << smallest << "\n\n";
getche();
}
Comment