Hi, I am new c++ programmer. I just learned about pointers, strings, arrays, getline() etc. I was solving this problem:
Write a C++ program that requests and displays information as shown in the following
example of output:
What is your first name? Betty Sue
What is your last name? Yew
What letter grade do you deserve? B
What is your age? 22
Name: Yew, Betty Sue
Grade: C
Age: 22
Note that the program should be able to accept first names that comprise more than one
word. Also note that the program adjusts the grade downward—that is, up one letter.
Assume that the user requests an A, a B, or a C so that you don’t have to worry about the
gap between a D and an F
.
Here's the code I came up with:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
// info.cpp -- information about people
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char first[20], last[20], grade[2];
int age;
cout << "What is your first name? ";
cin.getline(first, 20);
cout << "what is your last name? ";
cin.getline(last, 20);
cout << "What letter grade do you deserve? ";
cin >> grade;
cout << "What is your age? ";
cin >> age;
cout << "Name: " << last << ", " << first << endl;
cout << "Grade: " << grade << endl;
cout << "Age: " << age << endl;
return 0;
}
|
I realise that the grade needs to be adjusted downward, I don't understand how to do it. Any help would be appreciated.