Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

c++ beginner help

Status
Not open for further replies.

kevinmb

Programmer
Feb 28, 2004
2
US
I am having trouble passing a data value to a function. Here is my code:



void get_hand()
{
char card[3]("A");
int number(0),
score(0);

instructions();

cout << "How many cards are you holding? ";
cin >> number;
value_check(number);

do
{
cout << "Enter value of card " << number << ": ";
cin >> card;
calculate_score(score, card); //here's the problem
number--;
}while(number > 0);

return;
}

void calculate_score(int& score, char card)
{
cout << endl << score << endl;

return;
}



I get the following errors when I try to compile:

Error E2034 HW3.cpp 119: Cannot convert 'char *' to 'char' in function get_hand()
Error E2342 HW3.cpp 119: Type mismatch in parameter 'card' (wanted 'char', got 'char *') in function
get_hand()



Any help? Thanks!
 
Well the simple one-line change is

[tt]char card[3]("A");[/tt]

to

[tt]char card('A');[/tt]

--
 
The reason I don't do it that way is because I want a user to be able to input other values. The char card[3]("A"); line was just used to initialize the variable. But when it is read in from the keyboard, the user should be able to enter a value of one or two characters (hence, the [3] ). But it won't let me pass the value into a function.
 
In that case

[tt]void calculate_score(int& score, char card)[/tt]

becomes
[tt]void calculate_score(int& score, char card[])[/tt]

Don't forget to change the prototype of the function as well.

--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top