lundi 1 juin 2015

Trying programming with C, Getting Expected x before Y type error

Trying my hand at C (Self teaching and using The New Boston guides) but trying to make a simple ask these questions and then if the answer matches then print X or Y.

I have commented out yourAge as for what I'm doing i dont need it, It works if you remove the if statement and just have the print as Hi, firstName I can see that you're yourAge etc.

The error I'm getting is :

||=== Build: Debug in TestProject (compiler: GNU GCC Compiler) ===|
C:\Users\admin-jb\Desktop\TestCProject\TestProject\main.c||In function
'main':|
C:\Users\admin-jb\Desktop\TestCProject\TestProject\main.c|21|warning: implicit declaration of function 'If' [-Wimplicit-function-declaration]|
C:\Users\admin-jb\Desktop\TestCProject\TestProject\main.c|22|error: expected ';' before '{' token|
C:\Users\admin-jb\Desktop\TestCProject\TestProject\main.c|33|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|

Using Code::Blocks 13.12

Any ideas?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char firstName[20];
//    int  yourAge;
    char excelLike[20];


    printf("Please Enter Your Name?\n");
    scanf("%s", firstName);

//    printf("How old are you?\n");
//    scanf("%d", &yourAge);

    printf("Do you like Excel?\n");
    scanf("%s", excelLike);

    If(strcmp(excelLike, "yes") == 0)
        {
        printf("Hey, %s I love Excel too!!\n", firstName);
        }
    else
        {
        printf("Hey %s, pfft nor do I, its rubbish!\n", firstName);
        }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire