I am really new to C-language and was testing a simple if-statement program which, from your age and gender tells one answer from 4 different outcomes.
Which goes something like this: If you are under the age of 55 and are male, it will print: "You are a man at his best age!"
But I come across a error code which says: Run-Time Check Failure #2 - Stack around the variable 'miesVaiNainen' was corrupted.
I myself, think it might have something to do with: if (miesVaiNainen == "n" && age <= 55)
How can I fix this issue so the error wont come across?
I've tried to look for help in stackoverflow and tried to change the code a lot.
int age;
char manOrFemale;
printf("Are you a man or a female(m/f)");
scanf("%s", &manOrFemale);
printf("Input age:");
scanf("%d", &age);
if (manOrFemale == "f" && age <= 55)
{
printf("\nYou are a lady at her best!");
} else if (manOrFemale == "f" && age >= 56)
{
printf("\nYou look young for your age!");
}
if (manOrFemale == "m" && age <= 55)
{
printf("\nYou are a man at his best age!");
} else if (manOrFemale == "m" && age >= 56)
{
printf("\nYou are a wise man!");
} else {
printf("There has been an error in the program!");
}
}
Aucun commentaire:
Enregistrer un commentaire