First off, I just started learning how to use C a few days ago by using a 1988 version of C Primer Plus. I think it's a little outdated, and I'm about to burn this book. But here is my question; I'm trying to get the simple programs in the tutorials to stay open so I can see what is happening ( they close immediately). I found this script (don't even know if it is called a script) on this website:
it works when this is all that my program consists of, but when I try to add it to a program in one of the tutorials, such as:Code:#include <stdio.h> int main(void) /*wait for keypress*/ { int ch; printf ("Press [Enter] to continue"); while ((ch = getchar()) != '\n' && ch != EOF); return(0); }
it does not ask for me to hit enter, but just closes after running the commands.Code:#include <stdio.h> int main(void) /*wait for keypress*/ { float weight, value; char beep; beep = '\007'; printf("are you worth your weight in gold?\n"); printf("Please enter your weight in pounds, and we'll see.\n"); scanf("%f", &weight); value = 400.0*weight*14.5833; printf("%cYour weight in gold is worth $%2.2f%c.\n", beep,value,beep); printf("Your are easily worth that! If gold prices drop, "); printf("eat more\nto maintain your value.\n"); int ch; printf ("Press [Enter] to continue"); while ((ch = getchar()) != '\n' && ch != EOF); return(0); }
Did I enter something wrong?
If anyone helps with this simple problem, I am extremely greatful. I pretty much wasted a night on figuring this out, and I've given up searching for an answer on the web.
By the way, I'm using Dev-C++
Help me overcome! thanks



LinkBack URL
About LinkBacks





