By using this site, you agree to our Privacy Policy and our Terms of Use. Close

Forums - General - Borland C++ Excersice Help!!!

Ok, so there's yet another homework I'm unable to make, unlike the other ones I posted, I have not an idea how to do it.

So, I have to give 5 numbers, and I have to show the highest and lowest of them, but I'm forced to use one of these 3 commands:

while, do while or for (that's what we're studing now) help I don't know what to do.

EDIT: Just an example of stuff I use.

#include <iostream.h>

#include <conio.h>

int a,b,c,d,e;

void main()

{

cout<<"put first number: ";

cin>>a;

cout<<"put second number: ";

cin>>b;

cout<<"put third number: ";

cin>>c;

cout<<"put fourth number: ";

cin>>d;

cout<<"put fifth number: ";

cin>>e;

no idea

}



Around the Network

Is this any random number or 5 given numbers somebody types in?



Here's a basic code sample where it reads in 10 numbers typed on the console line. btw, Google needs to become your best friend as a developer otherwise you'll fail.

EDIT: I took original from google without reading if fully. Not sure if it worked.. I have written my own simplifed version after actually looking at other.

  • int max, min, num;
  •  
  • cout << "Enter number 1: ";
  • cin >> num;
  • max = num;
  • min = num;
  •  
  • for (int i = 1; i < 5; i"plusplus" ) {
  •    cout << "Enter number " << i   1 << ": ";
  •    cin >> num;
  •    //Check if num > max
  •    //Check if num < min
  • }
  • // max and min are now the largest/smallest values entered so post out answers
  • Haven't touched C"plusplus" in years so hopefully this gets you started and just fill in my commented areas.



    superchunk said:

    Is this any random number or 5 given numbers somebody types in?


    5 random numbers you type

    edit: also, please, I'd aprreciate that it's more simple, because I just know the most basic functions.



    Edited my last post as I copy/pasted before I actually read it thorougly. Now there is a better sample that is simple but unfinished as you should be able to fill in the missing parts.



    Around the Network

    If you have to use for necessarily, it'd do it this way

    int temp

    cin >> temp;

    int min =temp;

    int max = temp;

    for (int i = 1; i < 5; i plusplus){
         cin << temp;
         if (temp < min) min = temp;
         if (temp > max) max = temp
    }

    cout << min << " " << max << endl;

     

    Add couts at your leisure




    zexen_lowe said:

    If you have to use for necessarily, it'd do it this way

    int temp;

    cin >> temp;

    int min =temp;

    int max = temp;

    for (int i = 1, i < 5, i plusplus){
         cin << temp;
         if (temp < min) min = temp;
         if (temp > max) max = temp
    }

    cout << min << " " << max << endl;

     

    Add couts at your leisure

    That worked with little changes thanks, although I wasn't forced to use for, it was either "while, do while or for"



    HEY! That was essentially the same example I gave you.



    superchunk said:

    HEY! That was essentially the same example I gave you.


    Yeah, I noticed that :/

    But he made it more clear...........