1. #1
    Deleted

    Question Anyone good at programming?

    Hi
    I have this problem, I'm currently practicing for my exam at friday, the topic is programming. So i got the objective to make a program, where you input 3 number, and the program then sorts out which one of them is the highest number. Problem is, that i can't make it work the way i want it to. i got a little less than half done (first half is where the problem is), but i might need some advise concerning how to make the last part too.
    Here's how it looks so far:

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

    using namespace std;

    int main()
    {
    int a, b, c; //Here i'm defining a, b and c.

    a;
    cout<< "Please type a number: \n"; //You need to type the first number here.
    cin.get(); //As far as i understand, this gets the number
    //and uses it as output.
    b;
    cout<< "please type your second number: \n"; //Second number coming here
    cin.get();

    c;
    cout<< "please type your last number: \n"; //Last number is to be inserted here.
    cin.get();

    cout<<a <<b <<c <<endl; //This sums up what's written so far.

    }

    Ï could really use some help, since i've been using almost this whole week to prepare properly...

    The problem in it is, that when i run it, i can type the first number without any problems, but when i press enter after having typed first number, both the second and last line appears without me getting to type anything. I tried putting a "getch();" in between first and second line, that helped it from appearing immediatly, but i'm still not able to type anything after...
    Please, any help would be good.
    Thank you very much.

  2. #2
    Try
    cin << a;
    instead, or maybe
    cin.getline(a,10);

    And your program is not sorting the numbers, just displaying in order.
    Never going to log into this garbage forum again as long as calling obvious troll obvious troll is the easiest way to get banned.
    Trolling should be.

  3. #3
    I believe what you want to use is:

    cin >> a;

    If you don't have to store and output all of the numbers, that is, just the highest number is determined and output to the user in your final message, then a loop would be appropriate. Example:

    int HighestNum = 0; // declare and initialize your int variables
    int InputNum = 0;

    for (int i=0; i<3; i++){ //create a for loop to get 3 numbers from the user.
    cout << "Enter an integer number: "; //ask the user to input a number.
    cin >> InputNum; //get that number and store it in the variable InputNum.
    if (HigestNum < InputNum) //check to see if the new number is higher than the value stored in the HighestNum variable.
    HighestNum = InputNum; //store the new number as the highest if it is in fact highter.
    cout << endl; //move to the next line to start the process over again.
    }
    cout << " The highest number was: " << HighestNum; //output your final message with the highest number.
    Last edited by Dizey; 2011-05-12 at 01:06 AM.

  4. #4
    Deleted
    Wow thanks for the great help
    Now i can get going with my work. thank you again

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •