Need help writing a switch program for class

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

Need help writing a switch program for class

 
1
  #1
Sep 16th, 2006
I got this assignment to write a program using the switch statement or the functional decomposition, that inputs a letter and outputs thr corresponding international Alpabet.

A Alpha
B Bravo
C Charlie

so on and so on

Is there anybody that can help me with this program?
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: Need help writing a switch program for class

 
0
  #2
Sep 16th, 2006
  1. switch(value)
  2. {
  3. case possibleValue1:
  4. // do something
  5. break;
  6. case possibleValue2:
  7. // do something
  8. break;
  9. /* ... */
  10. default: // value wasn't any of possibleValue[1,n]
  11. // do something
  12. }
Post some code, or some sort of attempt if you want more help
Reply With Quote Quick reply to this message  
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

Re: Need help writing a switch program for class

 
0
  #3
Sep 16th, 2006
what do you mean by do something is that the alpabet word like Alpha
for the A character if it was entered?
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: Need help writing a switch program for class

 
0
  #4
Sep 16th, 2006
use something like this:
  1. switch(tolower(letter))
  2. {
  3. case 'a':
  4. cout << "Alpha"; // or return, if this is just a function
  5. break; // don't need this if you use return above
and repeat for all the letters.
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,410
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 247
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need help writing a switch program for class

 
1
  #5
Sep 16th, 2006
That's icky, but it's a start.

How about you post an attempt, wheelz?
"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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Need help writing a switch program for class

 
1
  #6
Sep 16th, 2006
One quick solution would be to create a parallel array.

  1.  
  2. array one =
  3. [ "a",
  4. "b",
  5.  
  6. ]
  7.  
  8. array two =
  9. [ "alpha",
  10. "bravo",
  11. ]

Then you match each by their corresponding index offset.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
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

Re: Need help writing a switch program for class

 
0
  #7
Sep 16th, 2006
Originally Posted by wheelz View Post
I got this assignment to write a program using the switch statement or the functional decomposition, that inputs a letter and outputs thr corresponding international Alpabet.

A Alpha
B Bravo
C Charlie

so on and so on

Is there anybody that can help me with this program?
This is what I have so far but it still doesn't work! I don't have a clue of what or how I am to start this program I don't even know how to put the code into this chat box so I just attached the file will that work??
Attached Files
File Type: cpp SwitchPP1.cpp (1.3 KB, 10 views)
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 147
Reputation: Grunt has a spectacular aura about Grunt has a spectacular aura about 
Solved Threads: 12
Grunt's Avatar
Grunt Grunt is offline Offline
Junior Poster

Re: Need help writing a switch program for class

 
1
  #8
Sep 16th, 2006
Add this before switch
  1. char letter;
  2. cin>>letter;
The key to eliminating bugs from your code is learning from your mistakes.
Reply With Quote Quick reply to this message  
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

Re: Need help writing a switch program for class

 
0
  #9
Sep 16th, 2006
I add The
char letter;
cin>>letter;

and now I have a fatal error C1010 unexpected end of file
while looking for precompiled header directive
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,266
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 377
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Need help writing a switch program for class

 
0
  #10
Sep 16th, 2006
Originally Posted by wheelz View Post
I add The
char letter;
cin>>letter;

and now I have a fatal error C1010 unexpected end of file
while looking for precompiled header directive
Did you change anything else?
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

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



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC