Hi everyone,

I'm taking a C programming class and in addition to being unfamiliar with all of the syntax, I'm still learning my way around a new compiler. I'm currently writing a program that gets a user to input 3 numbers, then it will display the lowest to highest. My code is as follows:

/* Input 3 numbers and sort them lowest to highest */
#include <stdio.h>

int main( void )
{
	int a; //Input number 1
	int b; //Input number 2
	int c; //Input number 3

	printf( "Please enter three integers: " );
	scanf( "%d %d %d", &a, &b, &c );

	/* Compare numbers */
	if ( a < b ){
		if ( a < c ) {
			if ( b < c ) {
			printf( "From lowest to highest: %d, %d, %d", a, b, c );
		}
			else {
				printf( "From lowest to highest: %d, %d, %d", a, c, b );
			}
		else {
			printf( "From lowest to highest: %d, %d, %d", c, a, b );
		}
	else {
		if ( b < c ) {
			if ( a < c ) {
				printf( "From lowest to highest: %d, %d, %d", b, a, c );
			}
			else {
				printf( "From lowest to highest: %d, %d, %d", b, c, a );
			}
		else {
			printf( "From lowest to highest: %d, %d, %d", c, b, a );
		}
		}
		return 0;
	}

I keep coming back with errors. On lines 22, 25, 33 I am getting "error C2181: illegal else without matching if", but I have matching if else statements. On line 39 I'm getting "fatal error C1075: end of file found before the left brace '{'"

I'm sure the solutions are quite simple, but for the life of me I'm at a loss after rewriting this multiple ways. Any guidance is greatly appreciated. Thanks!

Just rewrite the skeleton and copy and paste the old information in

if( )
{
    if()
    {

    } //close inner if

    else
    {

    } //close inner else
} //close outer if

else
{



} //close outer else

Make little notes like that to yourself to verify you're closing them at the right place (just for now). The issue with yours is that you don't close down the inner if statements at the right spot.

This question has already been answered. Start a new discussion instead.