Hi.
I have a program that reads in 10 numbers in an array function then prints out some output. I need the input to be able to only input numbers and nothing else (characters etc). Here is the code.
Can u guys help me validate the input so that only numbers are allowed. Or at least let me know where i can find out about it as my C++ knowledge sucks lol.Code:#include<iostream> #include<iomanip> using namespace std; void maximum ( float [], float, float&, float&, int&, int& ); //Function Prototype int main() { const arraysize = 10; float num[arraysize], small, big; //Declaration int p, p1; for ( int i = 0; i < 10; i++ ){ cout << endl << "Enter number " << i + 1 << " :\t"; cin >> num[i]; //Array input } maximum ( num, arraysize, small, big, p, p1 ); //Function call cout << endl << "Smallest number" << setw(5) << ":" << small << endl; cout << endl << "Position is" << setw(9) << ":" << p << endl; cout << endl << "Biggest number" << setw(5) << ":" << big << endl; cout << endl << "Position is" << setw(8) << ":" << p1 << endl; return 0; } void maximum (float a[], float size, float& small, float& big, int& position, int& position1){ big = a[0]; small = a[1]; for ( int j = 0; j < size; j++ ){ //Conditions if ( a[j] <= small ){ small = a[j]; position = j + 1; } if ( a[j] >= big ){ big = a[j]; position1 = j + 1; } } }



LinkBack URL
About LinkBacks



