944,210 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1411
  • C++ RSS
Sep 16th, 2006
1

Help with the execution of this program

Expand Post »
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


C++ Syntax (Toggle Plain Text)
  1. #include "stdafx.h"
  2. # include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7.  
  8. {
  9. int a;
  10. char letter;
  11. cin>>letter;
  12.  
  13. cout << "Enter a single capitalize character, Example A:";
  14. cin >> letter;
  15.  
  16. switch (letter)
  17. {
  18. case 'A': cout << "ALPHA"; // do something
  19. break;
  20. case 'B': cout << "Bravo"; // do something
  21. break;
  22. case 'C': cout << "Charlie";
  23. break;
  24. case 'D': cout << "Delta";
  25. break;
  26. case 'E': cout << "Echo";
  27. break;
  28. case 'F': cout << "Foxtrot";
  29. break;
  30. case 'G': cout << "Gulf";
  31. break;
  32. case 'H': cout << "Hotel";
  33. break;
  34. case 'I': cout << "India";
  35. break;
  36. case 'J': cout << "Juliet";
  37. break;
  38. case 'K': cout << "Kilo";
  39. break;
  40. case 'L': cout << "Lima";
  41. break;
  42. case 'M': cout << "Mike";
  43. break;
  44. case 'N': cout << "November";
  45. break;
  46. case 'O': cout << "Oscar";
  47. break;
  48. case 'P': cout << "Papa";
  49. break;
  50. case 'Q': cout << "Quebec";
  51. break;
  52. case 'R': cout << "Romeo";
  53. break;
  54. case 'S': cout << "Sierra";
  55. break;
  56. case 'T': cout << "Tango";
  57. break;
  58. case 'U': cout << "Uniform";
  59. break;
  60. case 'V': cout << "Victor";
  61. break;
  62. case 'W': cout << "Whiskey";
  63. break;
  64. case 'X': cout << "X-ray";
  65. break;
  66. case 'Y': cout << "Yankee";
  67. break;
  68. case 'Z': cout << "Zulu";
  69. break;
  70. default : cout << "Error";
  71. }
  72.  
  73.  
  74. cin >> a;
  75.  
  76. return 0;
  77. }
Last edited by Dave Sinkula; Sep 16th, 2006 at 9:51 pm. Reason: Added [code][/code] tags -- learn to use them yourself.
Similar Threads
Reputation Points: 18
Solved Threads: 0
Newbie Poster
wheelz is offline Offline
13 posts
since Sep 2006
Sep 16th, 2006
1

Re: Help with the execution of this program

Please don't double post
Reputation Points: 683
Solved Threads: 53
Posting Virtuoso
Infarction is offline Offline
1,580 posts
since May 2006
Sep 16th, 2006
2

Re: Help with the execution of this program

Hi wheelz,
You should check the input with While loop.It's something like this:
C++ Syntax (Toggle Plain Text)
  1. while((cin >> letter) != '0')
  2. {
  3. Your switch statement;
  4. And so... .;
  5. }

Good luck.
Reputation Points: 55
Solved Threads: 11
Junior Poster
mostafadotnet is offline Offline
157 posts
since Jul 2006
Sep 16th, 2006
1

Re: Help with the execution of this program

I don't think I understand the problem.
Click to Expand / Collapse  Quote originally posted by wheelz ...
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 !!!!!
So you prompt the user to enter a character.
Click to Expand / Collapse  Quote originally posted by wheelz ...
The prolem that I have is that you have to enter a character before it will start...
Ummm, isn't this the definition of "prompt the user to input a single character"? Why would this be a problem?

Click to Expand / Collapse  Quote originally posted by wheelz ...
... and it closes after just one entry
Bottom of the program:
C++ Syntax (Toggle Plain Text)
  1. case 'Z': cout << "Zulu";
  2. break;
  3. default : cout << "Error";
  4. }
  5.  
  6. cin >> a;
  7.  
  8. return 0;
  9. }
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 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.
Moderator
Reputation Points: 3280
Solved Threads: 897
Posting Sage
WaltP is offline Offline
7,753 posts
since May 2006
Sep 16th, 2006
0

Re: Help with the execution of this program

>>Also, #include "stdafx.h" i not necessary

It is with VC++ compilers and have precompiled headers turned on.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is online now Online
21,966 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: c++ File I/O Help
Next Thread in C++ Forum Timeline: Algorithm doubt





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC