If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Hybrid View

Help with a small class program?

Hello,

So I am new here, from what I have seen people here know what they're doing (not that my question is hard at all). So I am taking a programming class at my school. I have dabbled around with programming for a while, but never got very far. My teacher has given us some very simple programs to write, but I am a bit confused with this one. Here are the instructions to the assignment:

------------------

Write a C++ program that does the following:

Prompt the user to enter a day of the week as M (or m), T, W, R, F, S, and U for Monday through Sunday respectively. The user may enter an upper or lower case letter.

When the user enters a character, the program will echo the letter and output the name of the day of the week.

Provide an error trap that reads something like "you have entered an invalid letter; program aborting." Suggestion: use a switch statement with the error trap as the default condition. it is not necessary to prompt for multiple inputs.

-----------------

So I know how to get the program to echo back the letter and everything. What I am a little confused about is: will I have to define all the letters as their respective day? eg. make M== Monday. And if I do have to do that how would I get it to accept Upper and Lower case letters and recognize that that letter is == monday ect. ect.

Also my main problem is the switch statement as the error trap. I have never used the switch statement, but I know what they do. I just don't really understand how I would use it for an error trap. Am I suppose to just make a case for every other letter in the alphabet other then M T W R F S and U? Even if I do that then what if the user enters a number instead of a letter?

I am sorry if I am not making much sense... It makes sense in my head, hopefully its not too jumbled..

Re: Help with a small class program?

Alright, after a little bit more research I figured it out (at least I thought.) This is what I came up with:
#include <iostream>
using namespace std;
int main ()
{
int day;
cout << "Enter a letter that represents a day of the week: " << endl;
cin >> day;
cout << "The letter you entered is ." << day << endl;

When I ran the program I hit the letter 'm' and I got 'the letter you have entered is .0' and then it also stated the default error catching statement 'you have entered and invalid letter, program aborting'

* The Perfect Platform for Game Developers: Android
Developing rich, high performance Android games from the ground up is a daunting task. Intel has provided Android developers with a number of tools that can be leveraged by Android game developers.

* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.