Using a Void Function for Data Input.

i need help modifying this program to Create a function that has the following prototype: void getInputChar(string, char &);.

The function should display the string on the screen and then use cin to read a char from the keyboard.



#include <iostream>

using namespace std;


bool ignoreCaseCompare (char, char);

int main ()
{
char first = ' ';
char second = ' ';
char answer = ' ';

cout << "Enter a letter: ";
cin >> first;
cout << "Enter a letter: ";
cin >> second;

cout << "";
answer = ignoreCaseCompare (first, second);
cout << endl;

return 0;
}

bool ignoreCaseCompare (char one, char two)
{
one = toupper(one);
two = toupper(two);


if (one == two)
cout << "The two letters are the same. ";
else
cout << "The two letters are not the same. ";


system("pause");
return 0; }
//end main function


any help will be considered helpful thank you.
why would it be a problem?
1
2
3
4
5
6
7
8
9
#include <string> // don't forget to include the string definitions

...

void getInputChar(string s, char &ch)
{
  cout << s;
  cint >> ch;
}
everything is already in your code...
Topic archived. No new replies allowed.