ugly c++ problem  | |
January 23rd, 2006, 07:10 PM
|
#1 (permalink)
| | Member
Join Date: Oct 2005 Location: Australia
Posts: 58
|
I get a compilation error for the last line of the code
"in fuction 'main()' "
"in line 46 '}' expected"
even though i already have the '}' when i add another one it runs the program and
closes quickly (meaning there is an error)
any help would be apreciated! Code:
#include <iostream>
#include <cstdlib>
#include <ctime>
int hitme() {
int card;
srand(time(NULL));
card = rand()%11 + 0;
return(card);
}
using namespace std;
int main() {
int yc1, yc2, yc3, ytotal, ybank, ybet;
int cc1, cc2, cc3, ctotal, cbank, cbet;
char hors, bet;
ybank = 25;
cbank = 25;
cout<< "Welcome to blackjack!" << '\n' << '\n' << "Your cards are: ";
yc1 = hitme();
yc2 = hitme();
cc1 = hitme();
cc2 = hitme();
ytotal = yc1 + yc2;
ctotal = cc1 + cc2;
cout<< yc1 << " and " << yc2 << " with a total of: " << ytotal;
while (hors == 'h' || hors == 'H') {
cout << '\n' << '\n'<< "'H' to hit, 'S' to stay ";
cin >> hors;
if (hors != 'h' || hors != 'H'){
break;
}
yc3 = hitme();
ytotal = ytotal + yc3;
cout << '\n' << ytotal;
if (ytotal > 21){
cout << "BUST!!!";
break;
}
cout<< "Do you want to bet on winning? 'Y' for yes" << '\n';
cin >> bet;
if (bet == 'Y' || bet == 'y')
cin >> ybet;
cout<< '\n' << "You have: " << ybank << " chips. How many would you like to bet? " << '\n';
ybank = ybank - ybet;
cin.get();
return 0;
} |
| |
January 23rd, 2006, 07:18 PM
|
#2 (permalink)
| | Real gangstas sip on Yacc
Join Date: Oct 2001 Location: Suckas-ville
Posts: 4,552
|
You are missing a close brace on your while loop.
As far as it exiting right away your while condition is false when the program starts.
Either convert it to a do while or give hors an intial value.
Not all that ugly  When you add another brace and it complies you have a logic error.
Jkrohn
__________________
Signatures blow hard
If your signature contains an ad of any kind, congratulations, you're on my ignore list.
|
| |
January 23rd, 2006, 07:30 PM
|
#3 (permalink)
| | Member
Join Date: Oct 2005 Location: Australia
Posts: 58
|
OMG!! TY dude
i had been scratching my head chaning things around for about half an hour... |
| |
January 23rd, 2006, 09:07 PM
|
#4 (permalink)
| | Banned
Join Date: Oct 2005
Posts: 752
|
is that a blackjack prog...EXreaction u got some competiont  |
| |
January 23rd, 2006, 09:20 PM
|
#5 (permalink)
| | SoMuchAnime-SoLittleTime
Join Date: Aug 2003 Location: Plymouth, WI
Posts: 14,983
| |
| |
January 24th, 2006, 06:24 AM
|
#6 (permalink)
| | Member
Join Date: Oct 2005 Location: Australia
Posts: 58
|
lo im still working on it...  |
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |