I've read a few guides, copied and pasted example codes to test them, and even edited them to see how much I can change it without messing it up, but tonight I tried writing my own program from scratch. It compiles fine, but there's some problem in the execution. It's just a little program to impress my mother and ask if she wants a Dr Pepper float
Code:
#include <stdio.h>
char Choice;
char n;
char y;
int main()
{
printf("Would you like a Dr. Pepper float? (y/n)\n");
scanf("%c\n", &Choice);
if (Choice==y)
{
printf("Coming right up!\n");
}
else if (Choice==n)
{
printf("Ok. Whenever you want one, just call.\n");
}
return(0);
}
The output:
Code:
[milan@localhost ~]$ gcc drp.c -o drp
[milan@localhost ~]$ ./drp
Would you like a Dr. Pepper float?
y
y
[milan@localhost ~]$ ./drp
Would you like a Dr. Pepper float?
n
n
[milan@localhost ~]$
What I intended is for her to type y/n and see "Coming right up"/"Ok...".
Instead, I have to type y or n twice and the program then terminates. I imagine this is some absurdly simple thing I've done wrong...
Oh, another problem I've been having: I tried to use
gcc prog.c -o prog.exe
to compile a program to an executable so my mother could run it on her Windows machine, but all she gets is a DOS prompt that sits there and does nothing. Am I not able to compile to an exe on a Linux box?