Another Program Exercise (noob) having trouble with solution..

**I can't figure out how to subtract one from my char array... If someone could help me out, or post a more convenient solution to this problem (i'm pretty sure i'm going way out of my way to solve this..) I'd much appreciate it. My code is after the exercise in case you are a viewer who wants to try the exercise, its beginner level.**



Exercise : Write a C++ program that requests and displays information as shown in the following example of output:

What is your first name? John
What is your last name? Doe
What is your age?
What letter grade do you deserve? B

Name : Doe, John
Age : 22
Grade : C

Note that the pgraom should be able to accept first names that compromise more than one word. Also note that the pgraom adjusts hte grade downward, that is up on letter. Assume that the user request an A, B, or C so that you don't have to worry about the gap between a D and an F.


my code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
#include <string>
#include <cstring>

using namespace std;



int main()
{

    
    const int firstname = 20;
    char name[firstname];
    char lastname[firstname];
    int age;
    char grade[3]={'A','B','C'};
    
    cout << "What is your first name?\n";
    cin.getline(name, firstname);
    cout << "What is your last name?\n";
    cin.getline(lastname, firstname);
    cout << "What is your age?\n";
    cin >> age;
    cout << "What letter grade do you deserve?\n";
    cin >> grade;
    grade = grade - 1;
    

    cout << "Name : " << lastname << " , " << name << endl;
    cout << "Age : " << age << endl;
    cout << "Grade : " << grade << endl;
    
    
    
    cin.get();
    cin.get();
    return 0;
    
 

}
In the ASCII character set, the letter B is a higher number than the letter A. You want grade++;
I actually managed to figure it out thanks to your tip LB, it was actually in line 27

the code i should have been using was

grade[0] = ++grade[0];

:D feels so great to know!
Topic archived. No new replies allowed.