help

This is a discussion on help within the C++ Programming forums, part of the General Programming Boards category; Write a program in C++ that takes three int values interactively from the user and prints them in ascending order. ...

  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    32

    help

    Write a program in C++ that takes three int values interactively
    from the user and prints them in ascending order. with max and min

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    Post the code you have so far.

  3. #3
    Registered User
    Join Date
    Mar 2009
    Posts
    32
    Code:
    #include<stdio.h>
    
    int maximum ( int x, int y, int z);
    
    int main(void)
    
    {
        int number1;
        int number2;
        int number3;
        
        printf( "Enter three integers:");
        scanf( "%d%d%d", &number1, &number2, &number3);
        
        
        
     printf( "Maximum is:%d\n", maximum( number1, number2, number3) );
        
        return 0;
    }
    
    int maximum( int x, int y, int z)
    
    {
        int max = x;
        
        if( y > max)
            max = y;
        if( z > max)
            max = z;
            
            return max;
            
            }
    i am not sure i did what the problem is asking.

  4. #4
    Registered User
    Join Date
    Feb 2009
    Posts
    42
    The problem asks you to print the three numbers in ascending order, not the maximum.

    Also, aren't you supposed to do this using C++ STL? You're using printf and scanf from <stdio.h>, which is a C library. If you're doing this exercise I assume you're learning C++ so you should probably use std::cin and std::cout from <iostream>. Oh, and change int main (void) to int main().

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21