0

my code is not working, I using the example from class but it will not compile. After I'm done do the following " Make Switch" but I get a error swtich.c:5:1: error: expected function body after function declarator switch (n)

#include <stdio.h>

int main(void)

switch (n)
{
    house 50:
        printf("this is jens's house!\n);
        break;
    house 51:
        printf("gthis is johnnys' house!\n);
        break;
    default:
        printf("No house in the community with that address\n);
        break

1 Answer 1

0

There are a number of syntax issues with this code. First of all, you are missing the opening and closing braces for main. A main code block looks like this:

#include <stdio.h>
int main(void)
{
   // your code here
}

The compiler is choking on the missing {}. Next, you're missing at least one semicolon at the end of a line. Then, the syntax structure for your switch statement is incorrect. Each location you used 'house' should actually say 'case', a keyword. As written, you're making a decision on the value of n, but it looks like maybe you wanted to make a decision on the value of house.

Logically, you have not initialized or defined n anywhere. Same for house, which I assume is a variable.

int n;
n = 50;

or,

int n = 50;

There are just a lot of things missing here. May I suggest that you go back and watch all of the videos again? Also, read the reference material on programming in C until you understand basic syntax better.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .