How to fix this?

How to fix this?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <conio.h>
#include <stdio.h>

int main()
{
char status
int temp
clrscr();
printf("road status is (type S when safe or any letter when unsafe");
scanf ("%c", &status);
if ((status=='S')||(status=='s'))
printf ("Temperature > 0");
scanf ("%d", &temp);
  if(temp >= 0)
  printf ("wet road");
  else
  printf ("icy road");
else
printf ("drive carefully");
getch();
return 0;
}


The problem is when i try to compile it there's an error. ROAD.C 18: misplaced else
Last edited on
closed account (48T7M4Gy)
line 18 is your problem

if you use indentation you will be able to track down why there is an else problem
Last edited on
where can i find that indentation? im still beginner in c++. im studying every command on it :(
closed account (48T7M4Gy)
Indentation means you use tabs so you can see more clearly the structure of your program.

You should revise the if ... else structure and {} code blocks. You cant have if ... else ... else

1
2
3
4
5
6
7
8
9
10
if( ...)
{ 
    indent code;
    more indent code;
}
else
{
    indent code;
    more indent code 
}


There are tutorials here at this site or look at your book and notes.


You have also missed ; at end of lines in a couple of places
Last edited on
ok thx ill read them all
Topic archived. No new replies allowed.