I just need some clarification on what my homework assignment is telling me to do.

Ok, this is the homework question:

Write a program that reads a key pressed on the keyboard and displays its code on the screen. Use the program to determine the code for the Enter Key. Then write a function named ReadOneChar() that reads a character and ignores any succeeding characters until the Enter key is pressed. The entered character should be returned by ReadOneChar()

My code:

#include <iostream>
using namespace std;

int main()
{
	int Key;
	Key=getchar();
	cout << Key <<endl;
	return 0;
}

Ok, so what my code is doing right now is just prompting the user for an input, then displays the ASCII value of the input. So it works and it retrieves the value of the Enter key as needed.

What I do not understand is what the second part of the homework is asking. Can anyone clarify it for me? Is it just asking to return the first character of a string?

that function should take everything entered on the keyboard until the next enter, strip all but the first character from that string, and return only that first character.

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.