Limited The Code <?>

epenganteng (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#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 :)
NwN (770)
8
9
10
11
12
	for (int a=0; a<=7; a++)
	{
		cout<<"Value "<<a + 1<<" : ";
		cin>>Array[a];
	}


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.

All the best,
NwN
epenganteng (6)
@NwN please put in one @code so all done,this is my assignment for 1 week :)
MikeyBoy (235)
@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.
Registered users can post here. Sign in or register to post.