The assigment sounds like this : Write a C++ program that request and displays information as show in the following example of out:

What is your first name? Betty Sue
What is your last name? Yew
What letter of grade do you deserve? B
What is your age? 22
Name: Yew, Betty Sue
Grade: C
Age: 22

Here is my code for it... I dont know how to decrease the Char by one since you input Grade B, it should output C. Here is my code so far, hope someone can help me out :)

#include <iostream>

using namespace std;

int main(){


char firstName[20];
char lastName[20];
char letterGrade[] = "ABCDF";
int whatAge;





cout << "What is your first name? ";
cin >> lastName;

cout << "What is your last name? ";
cin >> firstName;

cout << "What letter grade do you deserve? ";
cin >> letterGrade;

cout << "What is your age? ";
cin >> whatAge;

cout << "Name: "<< lastName<< ", "<< firstName<<endl;
cout << "Grade: "<< letterGrade<<endl;
cout <<"Age: " << whatAge;

cin.get();
cin.get();
return 0;
}

Simply add one.

A char is simply a number output in a special way. B is the value 66, C is 67.

The prompts are reversed for first and last name.

Also, test your program with a two word first name (like Betty Sue) and see what happens...

Simply add one.

A char is simply a number output in a special way. B is the value 66, C is 67.

Can you explain more further in terms of code example. Im pretty new to programming and havent fully grasped arrays at all...

The prompts are reversed for first and last name.

Also, test your program with a two word first name (like Betty Sue) and see what happens...

That part works fine... The problem is the Grade thing.. When you input for instance C it should decrease by one and show D..

What is your first name? Jim Bob
What is your last name? What letter grade do you deserve? C
What is your age? 100
Name: Jim, Bob
Grade: C
Age: 100

It's not working fine when I enter a first name with a space, it skips over the last name prompt completely. Hint, you can't use cin when you have a space as it uses a space as a marker to stop taking in characters.

WaltP has given you an important clue. First you need to modify your array approach, as it's unnecessary. Take in a regular char. A char is a 1-byte integer, and therefore you can perform arithmetic on it.

What is your first name? Jim Bob
What is your last name? What letter grade do you deserve? C
What is your age? 100
Name: Jim, Bob
Grade: C
Age: 100

It's not working fine when I enter a first name with a space, it skips over the last name prompt completely. Hint, you can't use cin when you have a space as it uses a space as a marker to stop taking in characters.

WaltP has given you an important clue. First you need to modify your array approach, as it's unnecessary. Take in a regular char. A char is a 1-byte integer, and therefore you can perform arithmetic on it.

Thats the thing I dont know how to write the code for Char Array arithemetic subtraction. If there is a guide on the internet please post it I will read it and do from that.. I have just realized the other problem when want to show 2 names on the same line.. I dont want the code for it, just maybe some direction and toturial that specific shows/explains these problems. Ty for the input guys

deleted

Hi Here Is The Code Corrected You can modify

#include <iostream>

using namespace std;
int main()
{
    
char FirstName[20];
char LastName[20];
char Grade[6];
int age;


cout << "What is your first name?"<<endl;
cin >> FirstName;

cout << "What is your last name?"<<endl;
cin >> LastName;

cout << "What letter grade do you deserve?"<<endl;
cin >> Grade;

cout << "What is your age?"<<endl;;
cin >> age;

cout << "Name: "<<FirstName<< ", "<< LastName<<endl;
cout << "Grade: "<<Grade<<endl;
cout <<"Age: " <<age<<endl;

system("pause");
return 0;
}
commented: Do NOT do people's homework for them! They must do their own work. -3
What is your first name? Jim Bob
What is your last name? What letter grade do you deserve? C
What is your age? 100
Name: Jim, Bob
Grade: C
Age: 100

It's not working fine when I enter a first name with a space, it skips over the last name prompt completely. Hint, you can't use cin when you have a space as it uses a space as a marker to stop taking in characters.

WaltP has given you an important clue. First you need to modify your array approach, as it's unnecessary. Take in a regular char. A char is a 1-byte integer, and therefore you can perform arithmetic on it.

I figured I should use cin.get().get(); with the problem you stated, still havent figured the arithemetic..

Here is the new code:

#include <iostream>

using namespace std;

int main(){


char firstName[20];
char lastName[20];
char letterGrade[6];
int whatAge;





cout << "What is your first name? ";

cin.get(lastName, 20).get();

cout << "What is your last name? ";
cin >> firstName;


cout << "What letter grade do you deserve? ";
cin >> letterGrade;

cout << "What is your age? ";
cin >> whatAge;


cout << "Name: "<< lastName<< ", "<< firstName<<endl;
;
cout << "Grade: "<< letterGrade<<endl;
cout <<"Age: " << whatAge;

cin.get();
cin.get();
return 0;
}

You're close - you need cin.getline() (you have the parameters basically correct) to take in the whole line.

Try the following test program to see if it helps you understand the other part of the problem:

char x = 'a';
char y = 'd';
char z = '9';
	
std::cout << y - x<<std::endl;
std::cout << ++y <<std::endl;
std::cout << z - '0' <<std::endl;

Test different values of the letters and look at http://web.cs.mun.ca/~michael/c/ascii-table.html for reference.

You're close - you need cin.getline() (you have the parameters basically correct) to take in the whole line.

Try the following test program to see if it helps you understand the other part of the problem:

char x = 'a';
char y = 'd';
char z = '9';
	
std::cout << y - x<<std::endl;
std::cout << ++y <<std::endl;
std::cout << z - '0' <<std::endl;

Test different values of the letters and look at http://web.cs.mun.ca/~michael/c/ascii-table.html for reference.

Thx alot m8 I try it out tonight after some work.

As I said, a char is just another number that outputs as a letter.

char xchar;
cout << "Type a character:" << endl;
cin >> xchar;
xchar = xchar + 3;
cout << "The character is now " << xchar << endl;
cout << "It's new value is " << int(xchar) << endl;  // display the number value

Thx alot guys :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.