Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


c++

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
.exe
Cheater
Reputation: 0

Joined: 28 Dec 2009
Posts: 46

PostPosted: Thu Mar 10, 2011 8:29 am    Post subject: c++ Reply with quote

help me please. create a program that the user will be ask to input 3 numbers, find the lowest and highest number and print it out.
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Mar 10, 2011 8:44 am    Post subject: Reply with quote

Sounds like homework. I'll give you a few hints.

Pseudo code
Code:

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 >.>
Back to top
View user's profile Send private message
.exe
Cheater
Reputation: 0

Joined: 28 Dec 2009
Posts: 46

PostPosted: Thu Mar 10, 2011 9:00 am    Post subject: Reply with quote

#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 Smile
Back to top
View user's profile Send private message
AhMunRa
Grandmaster Cheater Supreme
Reputation: 27

Joined: 06 Aug 2010
Posts: 1117

PostPosted: Thu Mar 10, 2011 9:42 am    Post subject: Reply with quote

You are nearly there.

Code:

#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

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 >.>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites