| | |
Simple Program will not exit gracefully
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Apr 2005
Posts: 3
Reputation:
Solved Threads: 0
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): ");
Any help would be greatly appreciated!
<< moderator edit: added [code][/code] tags >>
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): ");
C++ Syntax (Toggle Plain Text)
/*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 >>
•
•
•
•
Originally Posted by Starz20
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.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- Need advice & help with a very simple program (IT Professionals' Lounge)
- a simple C program to create/open/write/close files generaing basic arithmetic ops (C)
- Erroneus outputs in string manipulation simple program (C++)
- pls i need help in this simple program of arrays... (C)
- Simple C++ program terminate prematurely (C++)
- I am a girl doing my 1st simple program (C)
Other Threads in the C++ Forum
- Previous Thread: what is the error
- Next Thread: Strings and For Loops
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings struct temperature template test text text-file tree url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






