I have 7 different inputs. And I'm only in the easiest class for computer science and I'm so lost.
So in all reality I just need the simplest way to find min and max values for 7 different inputs, in the C++ program language
I need to find a min for an array in C++.?
#include %26lt;limits%26gt;
#include %26lt;iostream%26gt;
using namespace std;
int main (void)
{
int maxVal = INT_MIN;
int minVal = INT_MAX;
int valueArray[7];
for (int i = 0; i %26lt; 7; i++)
{
int newVal;
cout %26lt;%26lt; endl %26lt;%26lt; "Please enter a number: ";
cin %26gt;%26gt; newVal;
valueArray[i] = newVal;
if (newVal %26gt; maxVal) maxVal = newVal;// set max to smallest possible val
if (newVal %26lt; minVal) minVal = newVal;// set min to largest possible val
}
cout %26lt;%26lt; "The largest of the 7 values is : " %26lt;%26lt; maxVal %26lt;%26lt; endl;// new max val?
cout %26lt;%26lt; "The smallest of the 7 values is : " %26lt;%26lt; minVal %26lt;%26lt; endl;// new min val?
}
================ OUTPUT ==============
Please enter a number: 100
Please enter a number: -30
Please enter a number: 5
Please enter a number: 1001
Please enter a number: -6543
Please enter a number: 20
Please enter a number: -100
The largest of the 7 values is : 1001
The smallest of the 7 values is : -6543
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment