help with program

This is a discussion on help with program within the C Programming forums, part of the General Programming Boards category; Can someone help me with what I'm doing wrong. I'm getting "parse error before else" on the 19, 25, and ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    24

    help with program

    Can someone help me with what I'm doing wrong. I'm getting "parse error before else" on the 19, 25, and 31 line.
    Here is the assignment:Write a C program that takes as input three integers and then outputs them in sorted (ascending) order. Save your program in a file called p1.c. You don't have to handle the case with invalid inputs.
    Code:
    #include <stdio.h>
    int main(void)
    {
     int a, b, c, first, second, max;
     printf("Enter Number 1: \n");
     scanf("%d", &a);
     printf("Enter Number 2: \n");
     scanf("%d", &b);
     printf("Enter Number 3: \n");
     scanf("%d", &c);
    
     if ( a > b && a > c ) max=a;
     else if ( b > a && b > c ) max=b;
     else if ( c > a && c > b ) max=c;
     
     if ( max=a ) 
     {
      if ( b > c ) first= c; second= b;
      else first= b; second= c;
     }
    
     if ( max=b )
     {
      if ( a > c ) first= c; second= a;
      else first= a; second= c;
     } 
     
     if ( max=c )
     {
      if ( a > b ) first= b; second= a;
      else first= a; second= b;
     }
    
     printf("%d\n", first);
     printf("%d\n", second);
     printf("%d", max);
    
     return 0;
    
    }

  2. #2
    Registered User
    Join Date
    Sep 2007
    Posts
    1
    change Line 19 from
    Code:
    else first= b; second= c;
    to

    Code:
    else{first= b; second= c;}
    same for the other two errors

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    24
    I fixed those and now when I compile I get like 20 errors. Am I defining things wrong?

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    if ( max==a )
    == tests for equality, = is assignment.

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,751
    Post your latest code, with braces in all the places you've missed them so far.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 11:04 PM

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