#include<iostream.h>
#include<iomanip.h>
void main()
{
int i,j,smalltest,temp;
int Array[8];
cout<<"Put A Value !"<<endl;
for (int a=0; a<=7; a++)
{
cout<<"Value "<<a + 1<<" : ";
cin>>Array[a];
}
cout<<"Value Before Sorted:\n\n";
for(int k=0;k<=7;k++)
{
cout<<setw(3)<<Array[k];
}
for(i=0;i<=7;i++)
{
smalltest=i;
for(j=i+1;j<=7;j++)
{
if(Array[smalltest]>Array[j])
{
smalltest=j;
}
}
temp=Array[i];
Array[i]=Array[smalltest];
Array[smalltest]=temp;
}
cout<<"\n\nValue After Sorted:\n\n";
for(int l=0;l<=7;l++)
{
cout<<setw(3)<<Array[l];
}
cout<<"\n\n";
}
hi guys,the code above needs to be limited,how to make it "When we put the number larger than 99,the exe will close,or show some text : YOU PUT WRONG VALUE!",how?? tq :)
It's in this block that you're asking for input, so it would make sense to put the validation here.
The easiest way is probably:
* make temporary int
* cin >> temp_int
* if tmp_int is larger than 99, decrease the counter (a) by 1 and continue to the next iteration
* else, set Array[a] = temp_int
That should provide you all the info you need to get that sorted.
Please do let us know if you require any further help.
@NwN please put in one @code so all done,this is my assignment for 1 week :)
That's your job. We're not here to do your homework for you. We'll give advice on C++ issues, and we'll take a look at code to see where problems are. We're not going to write it for you.