Hi, everyone. You may have probably heard this a hundred times, but I am new to programming and I am taking an intro to C++ class. I have a program that I have written, but I can't understand why it will not exit gracefully.
This is what I have written, but if I type in "E" to exit, it loops to enter in a number again and doesn't exit.
printf("\nEnter one positive or negative number (1, 2, 3. . . or E to exit): ");
/*multiple lines comment - Program to display square and square root for a given number*/
#include <math.h>/*for sqrt( ) function*/
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
/*variable and data type*/
float x;
/*standard output*/
printf("Shannon says programming is hard!\n");
printf("\nEnter one positive or negative number (1, 2, 3. . . or E to exit): ");
/* Prompt for input again */ printf(">> ");
/*standard input*/
scanf("%f", &x);
printf("\nx = %f ", x);
printf("\nSquare for x is = %f", x * x);
//sqrt() is the predefined function, defined in math.h
printf("\nSquare root for x is = %f\n", sqrt(x));//print results;
return 0;//finished
}
Any help would be greatly appreciated!
<< moderator edit: added [code][/code] tags >>