Need help in c programming

andrej192

Prominent
Jul 7, 2017
1
0
510
#include <stdio.h>
#include <stdlib.h>

int main()
{//online test, 3 questions

char capital;

printf("Question number 1: \n");
printf("What is the capital of Spain? \n");
scanf(" %s", &capital);

if(capital == "Madrid"){
printf("Correct, move on to question 2 \n");
}
if(capital != "Madrid"){
printf("Incorrect, start over");
}


return 0;
}
I am having a problem here, whenever i run the program it always gives me the answer "Incorrect, start over", how do i fix it so it displays correctly?
 
Solution
Yeah, like what rgd1101 said, the char data type can only hold one character. You're going to have to use a char array like what ksham said.

Also, in addition to what ksham was talking about. If there are only two outcomes, use if and else. If you got a few outcomes, you can use if with else if statements, and else at the end for the last resort.
Yeah, like what rgd1101 said, the char data type can only hold one character. You're going to have to use a char array like what ksham said.

Also, in addition to what ksham was talking about. If there are only two outcomes, use if and else. If you got a few outcomes, you can use if with else if statements, and else at the end for the last resort.
 
Solution