GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 13-Sep-2006, 17:52
glacier glacier is offline
New Member
 
Join Date: Sep 2006
Posts: 14
glacier is on a distinguished road

program to find smallest and largest integer among 5 integer values


Hey friends,

I need to know if i am making any mistake while doing this.
I have to make a program finding out smallest and largest number among five user input integers. The biggest problem is I only have to use "if" statement.

Please help me at the earliest !!

CPP / C++ / C Code:
int main()
{

int a;
int b;
int c;
int d;
int e;
int largest, smallest;

cout << "Please enter first number: ";
 cin >> a ;

cout << "Please enter Second number: ";
 cin >> b ;

cout << "Please enter third number: ";
 cin >> c ;

cout << "Please enter fourth number: ";
 cin >> d ;

cout << "Please enter fifth number: ";
 cin >> e ;

if (a<b)
cout << smallest << ":" <<largest<<endl ;
if (a<c)
cout << smallest << ":" <<largest <<endl ;
if (a<d)  
cout << smallest << ":" <<largest<<endl ;
if (a<e)
cout << smallest << ":" <<largest<<endl ;

if (b<a)
cout << smallest << ":" <<largest <<endl ;
if (b<c)
cout << smallest << ":" <<largest<<endl ;
if (b<d)
cout << smallest << ":" <<largest<<endl ;
if (b<e)
cout << smallest << ":" <<largest<<endl ;

if (c<a)
cout << smallest << ":" <<largest<<endl ;
if (c<b)
cout << smallest << ":" <<largest<<endl ;
if (c<d)
cout << smallest << ":" <<largest<<endl ;
if (c<e)
cout << smallest << ":" <<largest<<endl ;
if (d<a)
cout << smallest << ":" <<largest<<endl ;
if (d<b)
cout << smallest << ":" <<largest<<endl ;
if (d<c)
cout << smallest << ":" <<largest<<endl ;
if (c<e)
cout << smallest << ":" <<largest<<endl ;

if (e<a)
cout << smallest << ":" <<largest<<endl ;
if (e<b)
cout << smallest << ":" <<largest<<endl ;
if (e<c)
cout << smallest << ":" <<largest<<endl ;
if (e<d)
cout << smallest << ":" <<largest<<endl ;

return 0;

}
Last edited by LuciWiz : 14-Sep-2006 at 00:33. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 13-Sep-2006, 23:09
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,243
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all

Re: program to find smallest and largest integer among 5 integer values


Quote:
Originally Posted by glacier
Hey friends,

I need to know if i am making any mistake while doing this.
Yes. A lot. First and foremost is you skipped reading the "Please Read This" post.

Quote:
Originally Posted by glacier
I have to make a program finding out smallest and largest number among five user input integers. The biggest problem is I only have to use "if" statement.
That's not a problem. You only need a 8 of them.

CPP / C++ / C Code:
int main()
{
    int a;
    int b;
    int c;
    int d;
    int e;
    int largest, smallest;

    cout << "Please enter first number: ";
    cin >> a ;

    cout << "Please enter Second number: ";
    cin >> b ;

    cout << "Please enter third number: ";
    cin >> c ;

    cout << "Please enter fourth number: ";
    cin >> d ;

    cout << "Please enter fifth number: ";
    cin >> e ;

    // What's the value of the variable "smallest" and "largest"?
    // Nothing was ever initialized.
    if (a<b)
    cout << smallest << ":" <<largest<<endl ;
    if (a<c)
    cout << smallest << ":" <<largest <<endl ;
    if (a<d)  
...
}
If you need the smallest value, start by loading a into smallest. Then test the rest of the variables against smallest and if any are smaller, replace.

Then do the same with largest.

At the end, output the result.
__________________

Age is unimportant -- except in cheese
 
 

Recent GIDBlogObservations of Iraq by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Here is a questions about detecting the smallest and the largest integers jenmaz C Programming Language 8 24-Nov-2004 08:06
Need help with my programs, please help. agentxx04 C Programming Language 1 23-Sep-2004 18:02
Please Help, problems writing newbie c program soulfly C Programming Language 14 04-Mar-2004 15:16
Please Help, problems writing c program REVISED soulfly C Programming Language 6 03-Mar-2004 13:57

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 16:01.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.