Thursday, April 21, 2011

4/21

So Ive been working on the following assignment the last 1-2 weeks:

Write a C++ program that prompts the user to input three numbers. 
The program should then output the numbers in ascending order.

Ive been having a lot of problems with it. After I find the first highest number I have to then find the number below that, which has been the main issue.


Ive tried redefining the variable used for the first number and then asking if this or that number is <= to it.


I think I'm getting very close to figuring it out at the moment.





#include <cstdlib>
#include <iostream>


using namespace std;


int main(int argc, char *argv[])
{
    
    
    int num1, num2, num3;
    int a, b, c;
    int greater;
    
    
    a = num1;
    b = num2;
    c = num3;
    
    
    
    cout << "input your first number: ";
    cin >> num1;
    cout << endl;
    
    cout << "input your second number: ";
    cin >> num2;
    cout << endl;
    
    cout << "input your third number: ";
    cin >> num3;
    cout << endl;
    
    if (num1 > num2 && num3)
     cout << num1;
     cout << endl;
       
       
       else if (num2 > num1 && num3)
        cout << num2;
        cout << endl;
            
            
       else(num3 > num1 && num2)
            cout << num3;
            cout << endl;
            
       if (num3 > num1 && num2)
          cout << num3;
          cout << endl;
          
          else
          cout << num2;
          cout endl;
            


    
    
    
    system("PAUSE");
    return EXIT_SUCCESS;


}






The issue I'm having now is that the compiler I'm using is saying that there is a syntax error before every "else" statement (end o line)

No comments:

Post a Comment