I can't find the error and also C2182 error: illegal else without matching if.

#include <stdio.h>

int main (void)
{
	int count=0;		//counter
	int hours;			//hours
	char choice;		//users choice for continuing
	float total=0;		//total charge



	//print display
	printf ("%-15s %-10s %-10s","Customer","Hours","Total Charge");


	//assinging customer number

	count++;

	//ask for # of hours
	printf("Please enter # of hours:\n");
	scanf ("%d",&hours);

	//calculating total parking charge
	if (hours<3) && (hours>0)
		total=2;
	else 
		if (hours>=10) && (hours<=24)
			total = 10;
		else
			if (hours > 3) && (hours < 19)
				total = (hours-3)*.5 + 2;
			else
				if (hours > 24)
					printf ("Invalid Entry...Try Again");
		//need to repeat if entry is incorrect


	//print display
	printf ("%10d %20d %15fl", count, hours, total);

	










return 0;
}

Recommended Answers

All 4 Replies

The first problem is line 25 -- count the ( and ) pairs. line 28 and 31 have the same problem if ( (hours<3) && (hours>0) )

Yes Syntax error in if statement.

Ya, there is syntax error as stated in the above post...Also i want to add that even if there is only one expression corresponding to an 'if' or 'else', try using braces, this eliminates the possiblity of any ambiguity or error in future and code becomes managable...

if
{
      /*Expression*/
         |
         |
         |
}

I hope you got the answer to your problem...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.