:wave:
I made this code
but I need to stop the input when the user types a character using this type of while loop. I tried many types to include this loop in my program but it doesn't work. :cry: thanks for your help
I made this code
Code:
#include <iostream>
using namespace std;
void Cloud(int[], int);
int main()
{
int i;
int Rain[5];
for (i=0;i<=4;i++){
cout<<"please input"<<endl;
cin>>Rain[i];
}
Cloud(Rain, 5);
system ("pause");
}
void Cloud( int array[], int size)
{int i,j,temp;
array[5];
for(int i = 0; i <size-1; i++)
{
for(j=i+1;j<=size-1;j++)
{
if(array[i]<array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
for(i=0;i<=size-1;i++){
cout <<endl<<array[i]<<endl;
}
}
but I need to stop the input when the user types a character using this type of while loop. I tried many types to include this loop in my program but it doesn't work. :cry: thanks for your help
Code:
cout<<"Please insert a number: ";
while (! ( cin >> y))
{
cin.clear ();
cin.ignore (1000000,'\n');
cout<<"Insert a number: ";
}
cout<<"The number you typed is: "<< y << "\n\n";