| | |
Help with the execution of this program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2006
Posts: 13
Reputation:
Solved Threads: 0
I am a newbie to C++ and I'm not sure of anything at this point in time however,I got a problem with the starting phase of this program that well prompt the user to input a single character and output a inter4national Civil Aviation Word !!!!! The prolem that I have is that you have to enter a character before it will start and it closes after just one entry I don't see what is wrong!!!! Can somebody Help
Thanks for your time
Thanks for your time
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" # include <iostream> using namespace std; int main() { int a; char letter; cin>>letter; cout << "Enter a single capitalize character, Example A:"; cin >> letter; switch (letter) { case 'A': cout << "ALPHA"; // do something break; case 'B': cout << "Bravo"; // do something break; case 'C': cout << "Charlie"; break; case 'D': cout << "Delta"; break; case 'E': cout << "Echo"; break; case 'F': cout << "Foxtrot"; break; case 'G': cout << "Gulf"; break; case 'H': cout << "Hotel"; break; case 'I': cout << "India"; break; case 'J': cout << "Juliet"; break; case 'K': cout << "Kilo"; break; case 'L': cout << "Lima"; break; case 'M': cout << "Mike"; break; case 'N': cout << "November"; break; case 'O': cout << "Oscar"; break; case 'P': cout << "Papa"; break; case 'Q': cout << "Quebec"; break; case 'R': cout << "Romeo"; break; case 'S': cout << "Sierra"; break; case 'T': cout << "Tango"; break; case 'U': cout << "Uniform"; break; case 'V': cout << "Victor"; break; case 'W': cout << "Whiskey"; break; case 'X': cout << "X-ray"; break; case 'Y': cout << "Yankee"; break; case 'Z': cout << "Zulu"; break; default : cout << "Error"; } cin >> a; return 0; }
Last edited by Dave Sinkula; Sep 16th, 2006 at 9:51 pm. Reason: Added [code][/code] tags -- learn to use them yourself.
Hi wheelz,
You should check the input with While loop.It's something like this:
Good luck.
You should check the input with While loop.It's something like this:
C++ Syntax (Toggle Plain Text)
while((cin >> letter) != '0') { Your switch statement; And so... .; }
Good luck.
I don't think I understand the problem.
So you prompt the user to enter a character.
Ummm, isn't this the definition of "prompt the user to input a single character"? Why would this be a problem?
Bottom of the program:
Output the information, accept a character (which reads the [enter] from above -- remember, you entered a letter AND the ENTER key) and exit. The only problem I see is the program probably doesn't wait at the end. Change the top
Also, #include "stdafx.h" i not necessary.
•
•
•
•
I am a newbie to C++ and I'm not sure of anything at this point in time however,I got a problem with the starting phase of this program that well prompt the user to input a single character and output a inter4national Civil Aviation Word !!!!!
•
•
•
•
The prolem that I have is that you have to enter a character before it will start...
Bottom of the program:
C++ Syntax (Toggle Plain Text)
case 'Z': cout << "Zulu"; break; default : cout << "Error"; } cin >> a; return 0; }
cin to getline to keep the input stream clean, read it into a string and move the first character of the string to letter and continue.Also, #include "stdafx.h" i not necessary.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- calculate the execution time of a program (C)
- how to minus the time (VB.NET)
- how to simultaneously run 2 programs by calling one from another (C)
- c++ compile warnings (C++)
- Help with compression program (C)
Other Threads in the C++ Forum
- Previous Thread: c++ File I/O Help
- Next Thread: Reading specific line in a file. / Searching
| Thread Tools | Search this Thread |
api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion count data database delete desktop directshow dll download dynamic encryption error file forms fstream function functions game getline givemetehcodez google graph gui homeworkhelper iamthwee ifstream input int integer java lib library linkedlist linker linux loop looping loops map math matrix memory newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive return string strings struct studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






