int intUserIn[3];
int lowestNum = 0, highestNum = 0;
// Get my 3 numbers
cout << "enter 3 numbers:";
for( int x = 0; x < 2; x++){
intUserIn[x] = cin.getline(intUserIn, 256);
}
// Compare for lowest and highest.
if ( intUserIn[0] < intUserIn[1] && intUserIn[0] < intUserIn[2]){
lowestNum = intUserInt[0];
}else if ( intUserIn[1] < intUserIn[0] && intUserIn[2] ){
lowestNum = intUserIn[1];
}else if ( intUserInt[2] < intUserIn[1] && intUserIn[2] < intUserIn[0]){
lowsetNum = intUserIn[2];
}
//Reverse above to find highest. Return lowest and highest in cout
Not the most efficient nor the best.
A better way for that last section is probably.
Code:
unsigned min = 65535, max = 0;
// This would be inside the for loop negating the last bit of code seen previously.
#
if (min > intUserIn) min = intUserIn;
#
if (max < intUserIn) max = intUserIn;
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,min=65535,max=0;
cout<<"Enter 3 number\n\n";
for(int i=1;i<=3;i++)
cin>>num;
if(min>num)
{
min=num;
}
if(max<num)
{
max=num;
}
cout<<"min\t"<<min;
cout<<endl;
cout<<"max\t"<<max;
cout<<endl;
getch();
}
--
that is my code
and i entered 3 number
8
15
1
the output is
min= -1
max= 1
--
im trying to work on this code, this is not my homework please help me thanks
int main(int argc, char *argv[])
{
int num, min = 65535, max = 0;
cout << "Enter 3 numbers\n\n";
for ( int i = 1; i <= 3; i++ ) // NOTE i <= 3
{
cin >> num;
if ( min > num) min = num;
if ( max < num) max = num;
}
cout<< "min\t"<< min;
cout<< "max\t"<< max;
cout<< "\n";
system("PAUSE");
return EXIT_SUCCESS;
}
_________________
<Wiccaan> Bah that was supposed to say 'not saying its dead' lol. Fixing >.>
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum