Full re-write- problems
I have re-written some 2 card draw code, trying to heed the advice i was previously given. Here is the section that seems to be causing problems in Dev C++.
I get loads of ''incompatible types in assignment'' errors, a fev ''invalid lvalue in assignment'' errors and loads of warnings : ''Warning: assignment makes integer from pointer without a cast. However, I declared nothing as a pointer. Any help would be a Godsend.
Thank you
Graham Hinchly
Here is the offending code:
if((numCard1 >> 10) || (numCard2 >> 10))
{
if (numCard1 == 11)
{
court = "Jack";
}
if(numCard2 == 11)
{
(int)court2 = "Jack";
}
if(numCard1 == 12)
{
court = "Queen";
}
if(numCard2 == 12)
{
court2 = "Queen";
}
if(numCard1 == 13)
{
court = "King";
}
if(numCard2 == 13)
{
court2 = "King";
}
else
{
(int)court = numCard1;
(int)court2 = numCard2;
}
if (suita == 1)
{
suitname = "Diamonds";
}
if (suita == 2)
{
suitname = "Hearts";
}
if (suita == 3)
{
suitname = "Spades";
}
else
{
suitname = "Clubs";
}
if (suitb == 1)
{
suitnameb = "Diamonds";
}
if (suitb == 2)
{
suitnameb = "Hearts";
}
if (suitb == 3)
{
suitnameb = "Spades";
}
else
{
suitnameb = "Clubs";
}
}
}
dealerCards()
{
dnumCard1 = (rand() % (cards));
dnumCard2 = (rand() % (cards));
if (dnumCard1 == dnumCard2)
{
dnumCard2 -= 1;
}
if ((dnumCard1 >> 10) || (dnumCard2 >> 10))
{
if (dnumCard1 == 11)
{
dcourt = "Jack";
}
if(dnumCard2 == 11)
{
dcourt2 = "Jack";
}
if(dnumCard1 == 12)
{
dcourt = "Queen";
}
if(dnumCard2 == 12)
{
dcourt2 = "Queen";
}
if(dnumCard1 == 13)
{
dcourt = "King";
}
if(dnumCard2 == 13)
{
dcourt2 = "King";
}
else
{
(int)dcourt = dnumCard1;
(int)dcourt2 = dnumCard2;
}
};
if (dsuita == 1)
{
dsuitname = "Diamonds";
}
if (dsuita == 2)
{
dsuitname = "Hearts";
}
if (dsuita == 3)
{
dsuitname = "Spades";
}
else
{
dsuitname = "Clubs";
}
if (dsuitb == 1)
{
dsuitnameb = "Diamonds";
}
if (dsuitb == 2)
{
dsuitnameb = "Hearts";
}
if (dsuitb == 3)
{
dsuitnameb = "Spades";
}
else
{
dsuitnameb = "Clubs";
}
}
result()
{
printf("\nWell, here comes the moment of truth...\n");
sleep(2);
printf("You got the %s of %s and the %s of %s.\n", court, suitname, court2, suitnameb);
printf("The dealer got %s of %s and the %s of %s\n", dcourt, dsuitname,dcourt2, dsuitnameb);
printf("Hang on, that means....\n");
total = numCard1 + numCard2;
dtotal = dnumCard1 + dnumCard2;
sleep(2);
printf("You got %d and dealer got %d. ", total, dtotal);
if (total >> dtotal)
{
bank += bet;
printf("You win!!! You now have $%d\a", bank);
system("PAUSE");
}
else
{
bank -= bet;
printf("You lose. Your balance now rests on $%d.\n Press 1 to exit.", bank);
msg = getchar();
if (msg == 1)
{
exit(1);
}
}
if (bank << 0)
{
printf("You are in minus figures.");
system("PAUSE");
exit(1);
}
}
***We were all beginners once, don't forget that...***
court = "Jack";
You can''t assign a string like that. You need to use the strcpy() function, like strcpy(court,"Jack").
(int)court = numCard1;
You can''t cast a string to an int.
==================
/* todo: insert cool sig */
Martee
Magnum Games.NET
You can''t assign a string like that. You need to use the strcpy() function, like strcpy(court,"Jack").
(int)court = numCard1;
You can''t cast a string to an int.
==================
/* todo: insert cool sig */
Martee
Magnum Games.NET
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
The incompatible types in assignments and lvalue errors are probably caused by the lines like
try using the string functions like so:
for the numbered cards:
Should take care of most of the errors.
The warnings are probably from the lines like:
which is trying to make court2 act as an integer, and then set the value to "Jack" (which is really a pointer to char)
hope this helps
court = "Jack";
try using the string functions like so:
#include ...char court[20];int numCard1;...sprintf(court, "Jack");
for the numbered cards:
sprintf(court, "%d", numCard1);
Should take care of most of the errors.
The warnings are probably from the lines like:
(int)court2 = "Jack";
which is trying to make court2 act as an integer, and then set the value to "Jack" (which is really a pointer to char)
hope this helps
if((numCard1 >> 10) || (numCard2 >> 10)){ if (numCard1 == 11) { court = "Jack"; } if(numCard2 == 11) { (int)court2 = "Jack"; } if(numCard1 == 12) { court = "Queen"; } if(numCard2 == 12) { court2 = "Queen"; } if(numCard1 == 13) { court = "King"; } if(numCard2 == 13) { court2 = "King"; } else { (int)court = numCard1; (int)court2 = numCard2; } if (suita == 1) { suitname = "Diamonds"; } if (suita == 2) { suitname = "Hearts"; } if (suita == 3) { suitname = "Spades"; } else { suitname = "Clubs"; } if (suitb == 1) { suitnameb = "Diamonds"; } if (suitb == 2) { suitnameb = "Hearts"; } if (suitb == 3) { suitnameb = "Spades"; } else { suitnameb = "Clubs"; } }}dealerCards(){ dnumCard1 = (rand() % (cards)); dnumCard2 = (rand() % (cards)); if (dnumCard1 == dnumCard2) { dnumCard2 -= 1; } if ((dnumCard1 >> 10) || (dnumCard2 >> 10)) { if (dnumCard1 == 11) { dcourt = "Jack"; } if(dnumCard2 == 11) { dcourt2 = "Jack"; } if(dnumCard1 == 12) { dcourt = "Queen"; } if(dnumCard2 == 12) { dcourt2 = "Queen"; } if(dnumCard1 == 13) { dcourt = "King"; } if(dnumCard2 == 13) { dcourt2 = "King"; } else { (int)dcourt = dnumCard1; (int)dcourt2 = dnumCard2; } }; if (dsuita == 1) { dsuitname = "Diamonds"; } if (dsuita == 2) { dsuitname = "Hearts"; } if (dsuita == 3) { dsuitname = "Spades"; } else { dsuitname = "Clubs"; } if (dsuitb == 1) { dsuitnameb = "Diamonds"; } if (dsuitb == 2) { dsuitnameb = "Hearts"; } if (dsuitb == 3) { dsuitnameb = "Spades"; } else { dsuitnameb = "Clubs"; }}
It is simple. You have a typecast on court, court2, dcourt, dcourt2 as integers then that won''t work to well. those lines should read:
court=itoa(numCard);
and use a switch statement why dontcha.
If you missed a great moment in history don't worry, it'll repeat itself.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement