I'm getting this error: term does not evaluate to a function taking 1 arguments on the bolded and underlined parts of this code. I know this code isnt that great...has some extra stuff it doesnt need, but I'm working on that. This is pretty much the first program I've made in C++, other then one or two small ones for assignments.

#include <iostream>
#include <cstdlib>
#include <string>
using std::string;
using namespace std;

int main()
{
    int random = rand(); 
    int money = 100;
    int bet;
    bool correctbet = false;
    int Hcard[10];
    int ccard[10];
    string hroyal[10];
    string croyal[10];
    int totalace = 0;
    int totalace2 = 0;
    int numcards;
    int totalh = 0;
    int totalc = 0;
    bool correctcards = false;
    int move;
    bool quit = false;
    bool done = false;
    bool hace = false;
    bool cace = false;
    bool down = false;

    do{
        while(correctcards == false && quit == false){
            hace = false;
    std::cout << "Enter 0 to quit.  Do you want one or two cards?" << std::endl;
    std::cin >> numcards;
    if(numcards == 0)
    {
        quit = true;
    }
    else if(numcards < 0){
        std::cout << "You Can not have less then one card!" << std::endl;
    }
    else if (numcards <= 2){
        correctcards = true;
    }
    else{
    std::cout << "You can not have more then two cards!" << std::endl;
    }
    }
    if(quit != true){
    while(correctbet == false){
    if(money >= 20){
    std::cout << "You have $" << money << ".  Mininum bet is $20.  How much do you want to bet?" << std::endl;
    std::cin >> bet;
    }
    if(money >= 20 && (bet < 20 && bet >= 0))
    {
        std::cout << "The mininum bet is $20!" << std::endl;
    }
    if(money < 20)
    {
    std::cout << "You have $" << money << ". Mininum bet is changed to $0.  How much do you want to bet?" << std::endl;
    std::cin >> bet;
    correctbet = true;
    }
    else if(bet < 0)
    {
    std::cout << "You can not bet less then zero!" << std::endl;
    correctbet = false;
    }
    else if(bet > money)
    {
        std::cout << "You do not have that much!" << std::endl;
        correctbet = false;
    }
    else{
        money -= bet;
        correctbet = true;
    }
    }
//users cards       
    std::cout << "Your cards: " << std::endl;
    //royal cards
    for(int i = 0; i < numcards; i++)
    {
        [B][U]Hcard[i] = 1 + random(10);[/U][/B]
        if(Hcard[i] == 10){
        [B][U]int ran = 1+random(16);[/U][/B]
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        hroyal[i] = "J";
        totalh += 10;
        std::cout << hroyal[i] << " ";
        }
        else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
        {
        hroyal[i] = "Q";
        totalh += 10;
        std::cout << hroyal[i] << " ";
        }
        else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
        {
        hroyal[i] = "K";
        totalh += 10;
        std::cout << hroyal[i] << " ";
        }
        else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
        {
            Hcard[i] = 10;
            totalh += 10;
            std::cout << Hcard[i] << " ";
        }
        }
        //regular cards
        else if(Hcard[i] == 1)
        {
        [B][U]int ran = 1+ran(8);[/U][/B]
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        Hcard[i] = 1;
        std::cout << Hcard[i] << " ";
        totalh += 1;
        }
        else{
            hroyal[i] = "A";
            std::cout << "Your new card: " << hroyal[i] << ".  You can chooe it to be a 1 or 11 later. ";
            hace = true;
        }
        }
        else{
        totalh += Hcard[i];
        std::cout << Hcard[i] << " ";
        }
    }
    std::cout << std::endl; 
//options hit, stay, double down
    while(move != 2)
    {
    std::cout << "\nYou have " << totalh << "\n1: hit \n2: stay \n3: double down" << std::endl;
    std::cin >> move;
    switch(move)
    {
    //hit
    case 1:
        Hcard[numcards+1] = 1 + ran(10);
        if(Hcard[numcards+1] == 10){
        [B][U]int ran = 1+ran(16);[/U][/B]
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        hroyal[numcards+1] = "J";
        totalh += 10;
        std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
        }
        else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
        {
        hroyal[numcards+1] = "Q";
        totalh += 10;
        std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
        }
        else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
        {
        hroyal[numcards+1] = "K";
        totalh += 10;
        std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
        }
        else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
        {
            Hcard[numcards+1] = 10;
            totalh += 10;
            std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
        }
        }
        else if(Hcard[numcards+1] == 1)
        {
        [B][U]int ran = 1+ran(8);[/U][/B]
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        Hcard[i] = 1;
        std::cout << "Your new card: " << Hcard[i] << " ";
        totalh += 1;
        }
        else{
            hroyal[i] = "A";
            std::cout << "Your new card: " << hroyal[i] << ". You can chooe it to be a 1 or 11 later." << std::endl;
            hace = true;
        }
        }
        else{
        totalh += Hcard[numcards+1];
        std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
        }
        break;
    //stay
    case 2:
        move = 2;
        break;
    //double down
    case 3:
        down = true;
        money -= bet;
        bet = bet*2;
        Hcard[numcards+1] = 1 + ran(10);
        if(Hcard[numcards+1] == 10){
        [B][U]int ran = 1+ran(16);[/B][/U]
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        hroyal[numcards+1] = "J";
        totalh += 10;
        std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
        }
        else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
        {
        hroyal[numcards+1] = "Q";
        totalh += 10;
        std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
        }
        else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
        {
        hroyal[numcards+1] = "K";
        totalh += 10;
        std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
        }
        else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
        {
            Hcard[numcards+1] = 10;
            totalh += 10;
            std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
        }
        }
        else if(Hcard[numcards+1] == 1)
        {
        [B][U]int ran = 1+ran(8);[/U][/B]
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        Hcard[i] = 1;
        std::cout << "Your new card: " << Hcard[i] << " ";
        totalh += 1;
        }
        else{
            hroyal[i] = "A";
            std::cout << "Your new card: " << hroyal[i] << ". You can chooe it to be a 1 or 11 later.";
            hace = true;
        }
        }
        else{
        totalh += Hcard[numcards+1];
        std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
        }
        move = 2;
        break;
    default:
        std::cout << "Error: Not a command" << std::endl;
        break;
    }
    if(totalh > 21)
    {
        std::cout << "Bust! You have " << totalh << "!" << std::endl;
        move = 2;
    }
    else if(totalh == 21)
    {
        std::cout << "You got 21!!"<< std::endl;
        move = 2;
    }
    }
    move = 0;
    if(hace == true)
    {
        std::cout << "You have " << totalh << ". Do you want the ace to be 1 or 11?" << std::endl;
        std::cin >> totalace;
        totalh += totalace;
    }
//computers cards
    std::cout << "Computer's cards: ";
    while(done == false){
    //royal cards
    for(int x = 0; x < 1; x++)
        {
        [B][U]ccard[x] = 1 + ran(10);[/U][/B]
        if(ccard[x] == 10){
        int ran = 1+ran(16);
        if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
        {
        croyal[x] = "J";
        totalc += 10;
        std::cout << croyal[x];
        }
        else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
        {
        croyal[x] = "Q";
        totalc += 10;
        std::cout << croyal[x];
        }
        else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
        {
        croyal[x] = "K";
        totalc += 10;
        std::cout << croyal[x];
        }
        //regular cards
        else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
        {
            ccard[x] = 10;
            totalc += 10;
            std::cout << ccard[x];
        }
        }
        else if(ccard[i] == 1)
        {
        int ran2 = 6; //+ ran(8);
        if(ran2 == 1 || ran2 == 2 || ran2 == 3 || ran2 == 4)
        {
        ccard[i] = 1;
        totalc += 1;
        std::cout << ccard[i];
        }
        else if(ran2 == 5|| ran2 == 6|| ran2 == 7|| ran2== 8){
        croyal[x] = "A";
        cace = true;
        std::cout << croyal[x];
        }
        }
        else{
        totalc += ccard[x];
        std::cout << ccard[x];
        }

        if(totalc > 21){
        std::cout << std::endl << "Computer busted!" << std::endl;
        done = true;}
        else if(totalc == 21)
        done = true;
        else if(totalc < 15)
        ccard[x] = 1 + ran(10);
        else if(totalc >= 15)
            done = true;
    }
    std::cout << " ";
    }
    done = false;
    std::cout << std::endl;
    if(cace == true)
    {
    if(totalc > 10)
    {
    totalc +=1;
    }
    if(totalc <= 10){
    totalc += 11;
    }
    }
    if(totalc > 21 && totalh > 21)
    {
        std::cout << "I have " << totalc << " and you have " << totalh << " so we both lost :(" << std::endl;
    }
    else if(totalc > 21){
        std::cout << "I have " << totalc << " and you have " << totalh << " so you win!" << std::endl;
        money += bet*2;
    }
    else if(totalh > 21)
    {
        std::cout << "I have " << totalc << " and you have " << totalh << " so I win!" << std::endl;
        if(down == true)
        money -= bet;
    }
    else if(totalc == totalh)
    {
        std::cout << "I have " << totalc << " and you have " << totalh << " so we draw" << std::endl;
        money += bet;
    }
    else if(totalc > totalh)
    {
        std::cout << "I have " << totalc << " and you have " << totalh << " so I win!" << std::endl;
        if(down == true)
        money -= bet;
    }
    else if(totalc < totalh)
    {
        std::cout << "I have " << totalc << " and you have " << totalh << " so you win!" << std::endl;
        money += bet*2;
    }
    std::cout << "You have $" << money << std::endl;
    totalh = 0;
    totalc = 0;
    correctcards = false;
    correctbet = false;
    }
    }
    while(money > 0 && quit == false);
    if(money <=0){
        std::cout << "You lost!!" << std::endl;
    }
    else{
        std::cout << "You ended with: $" << money << "!!" << std::endl;
    }
    return 0;
}

Recommended Answers

All 5 Replies

#include <iostream>
#include <cstdlib>
#include <string>
using std::string;
using namespace std;

int main()
{
	int random = rand();
	int money = 100;
	int bet;
	bool correctbet = false;
	int Hcard[10];
	int ccard[10];
	string hroyal[10];
	string croyal[10];
	int totalace = 0;
	int totalace2 = 0;
	int numcards;
	int totalh = 0;
	int totalc = 0;
	bool correctcards = false;
	int move;
	bool quit = false;
	bool done = false;
	bool hace = false;
	bool cace = false;
	bool down = false;

	do{
		while(correctcards == false && quit == false){
			hace = false;
			std::cout << "Enter 0 to quit. Do you want one or two cards?" << std::endl;
			std::cin >> numcards;
			if(numcards == 0)
			{
				quit = true;
			}
			else if(numcards < 0){
				std::cout << "You Can not have less then one card!" << std::endl;
			}
			else if (numcards <= 2){
				correctcards = true;
			}
			else{
				std::cout << "You can not have more then two cards!" << std::endl;
			}
		}
		if(quit != true){
			while(correctbet == false){
				if(money >= 20){
					std::cout << "You have $" << money << ". Mininum bet is $20. How much do you want to bet?" << std::endl;
					std::cin >> bet;
				}
				if(money >= 20 && (bet < 20 && bet >= 0))
				{
					std::cout << "The mininum bet is $20!" << std::endl;
				}
				if(money < 20)
				{
					std::cout << "You have $" << money << ". Mininum bet is changed to $0. How much do you want to bet?" << std::endl;
					std::cin >> bet;
					correctbet = true;
				}
				else if(bet < 0)
				{
					std::cout << "You can not bet less then zero!" << std::endl;
					correctbet = false;
				}
				else if(bet > money)
				{
					std::cout << "You do not have that much!" << std::endl;
					correctbet = false;
				}
				else{
					money -= bet;
					correctbet = true;
				}
			}
			//users cards
			std::cout << "Your cards: " << std::endl;
			//royal cards
			for(int i = 0; i < numcards; i++)
			{
				Hcard[i] = 1 + random(10);
				if(Hcard[i] == 10){
					int ran = 1+random(16);
					if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
					{
						hroyal[i] = "J";
						totalh += 10;
						std::cout << hroyal[i] << " ";
					}
					else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
					{
						hroyal[i] = "Q";
						totalh += 10;
						std::cout << hroyal[i] << " ";
					}
					else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
					{
						hroyal[i] = "K";
						totalh += 10;
						std::cout << hroyal[i] << " ";
					}
					else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
					{
						Hcard[i] = 10;
						totalh += 10;
						std::cout << Hcard[i] << " ";
					}
				}
				//regular cards
				else if(Hcard[i] == 1)
				{
					int ran = 1+ran(8);
					if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
					{
						Hcard[i] = 1;
						std::cout << Hcard[i] << " ";
						totalh += 1;
					}
					else{
						hroyal[i] = "A";
						std::cout << "Your new card: " << hroyal[i] << ". You can chooe it to be a 1 or 11 later. ";
						hace = true;
					}
				}
				else{
					totalh += Hcard[i];
					std::cout << Hcard[i] << " ";
				}
			}
			std::cout << std::endl;
			//options hit, stay, double down
			while(move != 2)
			{
				std::cout << "\nYou have " << totalh << "\n1: hit \n2: stay \n3: double down" << std::endl;
				std::cin >> move;
				switch(move)
				{
					//hit
				case 1:
					Hcard[numcards+1] = 1 + ran(10);
					if(Hcard[numcards+1] == 10){
						int ran = 1+ran(16);
						if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
						{
							hroyal[numcards+1] = "J";
							totalh += 10;
							std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
						}
						else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
						{
							hroyal[numcards+1] = "Q";
							totalh += 10;
							std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
						}
						else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
						{
							hroyal[numcards+1] = "K";
							totalh += 10;
							std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
						}
						else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
						{
							Hcard[numcards+1] = 10;
							totalh += 10;
							std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
						}
					}
					else if(Hcard[numcards+1] == 1)
					{
						int ran = 1+ran(8);
						if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
						{
							Hcard[i] = 1;
							std::cout << "Your new card: " << Hcard[i] << " ";
							totalh += 1;
						}
						else{
							hroyal[i] = "A";
							std::cout << "Your new card: " << hroyal[i] << ". You can chooe it to be a 1 or 11 later." << std::endl;
							hace = true;
						}
					}
					else{
						totalh += Hcard[numcards+1];
						std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
					}
					break;
					//stay
				case 2:
					move = 2;
					break;
					//double down
				case 3:
					down = true;
					money -= bet;
					bet = bet*2;
					Hcard[numcards+1] = 1 + ran(10);
					if(Hcard[numcards+1] == 10){
						int ran = 1+ran(16);
						if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
						{
							hroyal[numcards+1] = "J";
							totalh += 10;
							std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
						}
						else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
						{
							hroyal[numcards+1] = "Q";
							totalh += 10;
							std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
						}
						else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
						{
							hroyal[numcards+1] = "K";
							totalh += 10;
							std::cout << "Your new card: " << hroyal[numcards+1] << std::endl;
						}
						else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
						{
							Hcard[numcards+1] = 10;
							totalh += 10;
							std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
						}
					}
					else if(Hcard[numcards+1] == 1)
					{
						int ran = 1+ran(8);
						if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
						{
							Hcard[i] = 1;
							std::cout << "Your new card: " << Hcard[i] << " ";
							totalh += 1;
						}
						else{
							hroyal[i] = "A";
							std::cout << "Your new card: " << hroyal[i] << ". You can chooe it to be a 1 or 11 later.";
							hace = true;
						}
					}
					else{
						totalh += Hcard[numcards+1];
						std::cout << "Your new card: " << Hcard[numcards+1] << std::endl;
					}
					move = 2;
					break;
				default:
					std::cout << "Error: Not a command" << std::endl;
					break;
				}
				if(totalh > 21)
				{
					std::cout << "Bust! You have " << totalh << "!" << std::endl;
					move = 2;
				}
				else if(totalh == 21)
				{
					std::cout << "You got 21!!"<< std::endl;
					move = 2;
				}
			}
			move = 0;
			if(hace == true)
			{
				std::cout << "You have " << totalh << ". Do you want the ace to be 1 or 11?" << std::endl;
				std::cin >> totalace;
				totalh += totalace;
			}
			//computers cards
			std::cout << "Computer's cards: ";
			while(done == false){
				//royal cards
				for(int x = 0; x < 1; x++)
				{
					ccard[x] = 1 + ran(10);
					if(ccard[x] == 10){
						int ran = 1+ran(16);
						if(ran == 1 || ran == 2 || ran == 3 || ran == 4)
						{
							croyal[x] = "J";
							totalc += 10;
							std::cout << croyal[x];
						}
						else if(ran == 5 || ran == 6 || ran ==7 || ran == 8)
						{
							croyal[x] = "Q";
							totalc += 10;
							std::cout << croyal[x];
						}
						else if(ran == 9 || ran == 10 || ran == 11 || ran == 12)
						{
							croyal[x] = "K";
							totalc += 10;
							std::cout << croyal[x];
						}
						//regular cards
						else if(ran == 13 || ran == 14 || ran == 15 || ran == 16)
						{
							ccard[x] = 10;
							totalc += 10;
							std::cout << ccard[x];
						}
					}
					else if(ccard[i] == 1)
					{
						int ran2 = 6; //+ ran(8);
						if(ran2 == 1 || ran2 == 2 || ran2 == 3 || ran2 == 4)
						{
							ccard[i] = 1;
							totalc += 1;
							std::cout << ccard[i];
						}
						else if(ran2 == 5|| ran2 == 6|| ran2 == 7|| ran2== 8){
							croyal[x] = "A";
							cace = true;
							std::cout << croyal[x];
						}
					}
					else{
						totalc += ccard[x];
						std::cout << ccard[x];
					}

					if(totalc > 21){
						std::cout << std::endl << "Computer busted!" << std::endl;
						done = true;}
					else if(totalc == 21)
						done = true;
					else if(totalc < 15)
						ccard[x] = 1 + ran(10);
					else if(totalc >= 15)
						done = true;
				}
				std::cout << " ";
			}
			done = false;
			std::cout << std::endl;
			if(cace == true)
			{
				if(totalc > 10)
				{
					totalc +=1;
				}
				if(totalc <= 10){
					totalc += 11;
				}
			}
			if(totalc > 21 && totalh > 21)
			{
				std::cout << "I have " << totalc << " and you have " << totalh << " so we both lost " << std::endl;
			}
			else if(totalc > 21){
				std::cout << "I have " << totalc << " and you have " << totalh << " so you win!" << std::endl;
				money += bet*2;
			}
			else if(totalh > 21)
			{
				std::cout << "I have " << totalc << " and you have " << totalh << " so I win!" << std::endl;
				if(down == true)
					money -= bet;
			}
			else if(totalc == totalh)
			{
				std::cout << "I have " << totalc << " and you have " << totalh << " so we draw" << std::endl;
				money += bet;
			}
			else if(totalc > totalh)
			{
				std::cout << "I have " << totalc << " and you have " << totalh << " so I win!" << std::endl;
				if(down == true)
					money -= bet;
			}
			else if(totalc < totalh)
			{
				std::cout << "I have " << totalc << " and you have " << totalh << " so you win!" << std::endl;
				money += bet*2;
			}
			std::cout << "You have $" << money << std::endl;
			totalh = 0;
			totalc = 0;
			correctcards = false;
			correctbet = false;
		}
	}
	while(money > 0 && quit == false);
	if(money <=0){
		std::cout << "You lost!!" << std::endl;
	}
	else{
		std::cout << "You ended with: $" << money << "!!" << std::endl;
	}
	return 0;
}

Line 85 and others. You defined random as an integer in line 9. I'm not sure what you are trying to do. An integer is not a function so if you are tying to call a function, you can't do it that way. Are you trying to call the rand () function to create some random integer? If so, what range are you trying to achieve?

ya, I'm trying to all the rand() function to create some random integer, between 1 and 10.

ya, I'm trying to all the rand() function to create some random integer, between 1 and 10.

O.K. Change line 85 to something like this:

Hcard[i] = 1 + rand () % 10;

rand () is the random number function. It returns an integer from 0 to some big number called RAND_MAX, which is 32,000 or something; depends on the compiler, I think. Anyway, too big of a range for you here. % is the mod operator. It takes the remainder after dividing by 10. The result is a number from 0 to 9, inclusive. Adding 1 to it makes it a number from 1 to 10.

thanks! that worked. Now I have one more error, it says that i is an undeclared identifier in 11 places that i is used.

never mind I gotit to work. thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.