cin.get()

Hello again. I would like to thank everybody for the help. I have another homework question.

I need to use the cin.get() in a user defined function. I can get it to work just fine out of the function I created but as soon as I put it in the function I created it does not work.

1
2
3
4
5
6
7
8
void wordToNumber(char word)
{
    cout << "Enter a seven letter word to be converted into a phone number: ";
    cin.get(word);
    
    cout << word << endl;
    
}


and this is how I call the function in the main after the prototype.

1
2
3
4
//local variables
    char words;
    
    wordToNumber(char words);


It says expected primary-expression before "char"
If your program isn't too long, can you copy paste it here so we can see? And if it's too big, use a free tool like pastebin or codepad and give us the link to it.

Edit: Ignore that. When you call the function, you don't include the data type of the variable you're passing. To put it simply, remove char from your call to wordToNumber in main.
Last edited on
Thank you so much. Dang it. It was an easy fix I am so confused with this homework ass. I think I am over thinking it. We have to create a program that converts words into phone numbers and I don't even know where to begin.
Create a digester function that takes an array of chars. The function should get each position and depending on the letter in each position the function should assign it a number in a new array and then print it to main
I would love to use an array but since the instructor has not talked about arrays we are not allowed to use them. We have to use the cin.get().
cin.get gives you only one char back
http://www.cplusplus.com/forum/general/465/

I think you need to run cin.get(word) a few times
for(i=0; i< 8 i++)
{
cin.get(word);
}

oohw and why do you get word as an variable in to the function but you don;t do anything with it

you can better replace it with void and define in the function
char word;
Topic archived. No new replies allowed.