Need help (I am a beginner with C)

This is a discussion on Need help (I am a beginner with C) within the C Programming forums, part of the General Programming Boards category; So I need to create a program where you input 3 integers and the programs will display the largest of ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    Need help (I am a beginner with C)

    So I need to create a program where you input 3 integers and the programs will display the largest of the 3. It's not quite working for me, here's what I have so far:

    Code:
    #include <stdio.h> 
    
    
    main()
    {
          float a, b, c;
          
          printf("Enter three numbers!\n");
          printf("Enter the first number: \n");
          scanf("%f" , &a);
          printf("Enter the second number: \n");
          scanf("%f" , &b);
          printf("Enter the third number: \n");
          scanf("%f" , &c);
          
          if (a > b , a > c)
          {
          printf("%f is the largest number!\n" , a);
          }
          else if (b > a, b > c)
          {
                printf("%f is the largest number!\n" , b);
                }
          else 
          {
               printf("%f is the largest number!\n" , c);
               }
               getch();
          return 0;
          
          }
    It works when "c" and "a" is the largest number, but when "b" is the largest number, it says "a" is the largest number.

    I'm probably making a total noob mistake because I only started C a few days ago. Thanks in advance for the help!


    [FONT='Times New Roman', Times, serif]
    [/FONT]

  2. #2
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    You want && instead of a comma in your if statements.
    Code:
    while(!asleep) {
       sheep++;
    }

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    Wow, it worked. Haha thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need some help for a beginner
    By wasabiman123 in forum C Programming
    Replies: 14
    Last Post: 08-17-2011, 09:43 PM
  2. Beginner Help Plz :D
    By xanimeangiex in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2010, 06:43 AM
  3. Beginner: help?
    By Baltz in forum C Programming
    Replies: 4
    Last Post: 11-12-2010, 02:50 AM
  4. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 10:21 AM
  5. C++ Beginner
    By Steevous in forum C++ Programming
    Replies: 1
    Last Post: 10-27-2002, 03:23 PM

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