I'm a noob, HELP!
 CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

# Thread: I'm a noob, HELP!

1. Junior Member
Join Date
Apr 2010
Posts
9

## I'm a noob, HELP!

So I'm writing an exercise/check-for-comprehension program. I have to write a program that asks, "What letter grade do you deserve?" Then, the user replies by entering in a letter (A,B, or C; D and F are left out because of the gap between the letters, and this is a novice program, so assume the user types A, B, or C). The program then says,"This is the grade you are going to get:" and displays one letter grade lower than the user entered. In other words, if I enter an A, I get a B, and if I enter a B, I get a C, and finally, if put C, I get a D.
I'm not allowed to use the IF and ELSE techniques. I'm guessing, by the nature of this program, I have to use pointer arithmetic methods.

2. Elite Member Power Poster
Join Date
Jan 2006
Location
Singapore
Posts
6,731

## Re: I'm a noob, HELP!

Well... although strictly speaking it is not portable, in practice, you will be using an ASCII based character set, so the characters 'A', 'B', 'C' and 'D' are in sequence such that 'A' + 1 == 'B', 'B' + 1 == 'C' and 'C' + 1 == 'D'. You can make use of this to compute the answer.

3. ## Re: I'm a noob, HELP!

You can't use if? What about use a switch?

4. Elite Member Power Poster
Join Date
Oct 2007
Location
Seattle, WA
Posts
10,895

## Re: I'm a noob, HELP!

What if you guess D?

5. Member +
Join Date
Aug 2008
Posts
902

## Re: I'm a noob, HELP!

So I'm writing an exercise/check-for-comprehension program. I have to write a program that asks, "What letter grade do you deserve?" Then, the user replies by entering in a letter (A,B, or C; D and F are left out because of the gap between the letters, and this is a novice program, so assume the user types A, B, or C). The program then says,"This is the grade you are going to get:" and displays one letter grade lower than the user entered. In other words, if I enter an A, I get a B, and if I enter a B, I get a C, and finally, if put C, I get a D.
I'm not allowed to use the IF and ELSE techniques. I'm guessing, by the nature of this program, I have to use pointer arithmetic methods.
Code:
```char grade = cin.get();
??? That was pretty easy.

6. Join Date
Feb 2010
Posts
28

## Re: I'm a noob, HELP!

This might help

Code:
```#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{

cout <<"What letter grade do you deserve?   ";

// changes the letter if it is lower case to uppercase

while( int(letterGrade) < 65 || int(letterGrade) > 70) // (A-F) from 65-70
{
cout <<"You did not enter a valid choice." << endl;
cout <<"Enter a letter from A-F :";

}

{
case 'A':

cout <<"The grade you deserve is a B!" << endl;
break;
case 'B':

cout <<"The grade you deserve is a C!" << endl;
break;
case 'C':

cout <<"The grade you deserve is a D!" << endl;
break;
case 'D':

cout <<"The grade you deserve is an F!" << endl;
break;
case 'F':
break;
cout <<"The grade you deserve is an F!" << endl;
}

return 0;
}```
You can substitute the pointer arithmetic what the user above me has written
Last edited by yellowMonkeyxx; April 18th, 2010 at 04:40 PM.

7. Elite Member Power Poster
Join Date
Oct 2007
Location
Seattle, WA
Posts
10,895

## Re: I'm a noob, HELP!

Pointer arithmetic is hardly required. Simply realizing that chars are basically integers is enough.

8. Junior Member
Join Date
Apr 2010
Posts
9

## Re: I'm a noob, HELP!

Oh my God, I feel stupid as hell now.

9. Elite Member Power Poster
Join Date
Nov 2003
Location
Florida
Posts
12,518

## Re: I'm a noob, HELP!

Originally Posted by yellowMonkeyxx
This might help

You can substitute the pointer arithmetic what the user above me has written
The user above you didn't use pointer arithmetic, and please don't do somebody's homework for them.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•