Help with the execution of this program

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2006
Posts: 13
Reputation: wheelz is an unknown quantity at this point 
Solved Threads: 0
wheelz wheelz is offline Offline
Newbie Poster

Help with the execution of this program

 
1
  #1
Sep 16th, 2006
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


  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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Help with the execution of this program

 
1
  #2
Sep 16th, 2006
Please don't double post
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 155
Reputation: mostafadotnet is on a distinguished road 
Solved Threads: 10
mostafadotnet's Avatar
mostafadotnet mostafadotnet is offline Offline
Junior Poster

Re: Help with the execution of this program

 
2
  #3
Sep 16th, 2006
Hi wheelz,
You should check the input with While loop.It's something like this:
  1. while((cin >> letter) != '0')
  2. {
  3. Your switch statement;
  4. And so... .;
  5. }

Good luck.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,117
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 282
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: Help with the execution of this program

 
1
  #4
Sep 16th, 2006
I don't think I understand the problem.
Originally Posted by wheelz View 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 !!!!!
So you prompt the user to enter a character.
Originally Posted by wheelz View Post
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?

Originally Posted by wheelz View Post
... and it closes after just one entry
Bottom of the program:
  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.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,494
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1478
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help with the execution of this program

 
0
  #5
Sep 16th, 2006
>>Also, #include "stdafx.h" i not necessary

It is with VC++ compilers and have precompiled headers turned on.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC