Pls check the code. for example during betting if you write "One"
if the dice comes 1, you win. but when you write one it writes 2.28 1026 why.
I dont want case sensitive and it would be perfect if the first and second character I write for input, it must do.

#include <iostream>	// 
#include <stdlib.h>		// 
#include <ctype.h>		// 
#include <time.h>		// 
#include <string.h>		// 

using namespace std;


int Burcin();		//   game function.


int main()
{

	double total_money;			// total money....
	double betting_money;			// betting money.
	char Exit = 'Y';	// Yes or no for the game.....


	cout<<"Welcome"<<endl<<endl;
	cout<<"how much money you have in your pocket? usd ";
	cin>>total_money;			// enter total money that you have
	cout<<endl<<endl;	// 

	// Loops working until no .... in turkish H
	while(toupper(Exit) != 'N')
	{
		cout<<"Betting!"<<endl<<endl;
		cout <<"now you have: "<<total_money<<endl;
		cout <<"how much you bet. ? $ ";      
		cin>>betting_money;     // betting money
		cout<<endl<<endl;

		total_money = total_money - betting_money; // substract betting money from your pocket money
		total_money = total_money + (betting_money * Burcin());	// Add winning bet;		
		// you dont have bucks....
		if (total_money < 1)
		{
			cout<<endl<<endl<<"find money !"; // find money....
  			cout	<<endl<<endl;
			break;
		}

		// 
		cout<<endl<<endl<<"do you want to play again (Y veya N)? "; // do you want to play
		cin>>Exit;	
		cout<<endl<<endl<<endl;
	}

	
	cout<<"thanks for playing with this program !"<<endl<<endl;
}


int Burcin()
{
    char answer[15]="";	// answer
	int Dice;			// dice to be rolled

	
	// Print the choices
	cout<<"[ One Two Three Four Five Six] "; // onee two three four five six
	// Prompt the user
	cout<<"\n\n\nwhich one you choose.? "<<endl;    // which one you prefer

	cin>>answer;	// Receive input 

	srand((unsigned)time( NULL ));
    Dice = rand() % 6+1;   // produce random for dice.

	cout <<"winning number "<<Dice<<" !"<<endl; // output number is....
	
	
// control reseult......
	if(strcmp(answer,"One") == 0)
	{
		if (Dice == 1)
		{
			cout<<"you win !"<<endl; // you win
			return 6; // you win 6 times from your bet.
		}
		else
		{
			cout<<"you lose !"<<endl; // you lose
			return 0;
		}
    }
	if(strcmp(answer,"Two") == 0)
	{
		if (Dice == 2)
		{
			cout<<"you win!"<<endl;
			return 6;
		}
		else
		{
			cout<<"you lose!"<<endl;
			return 0;
		}
    }
	if(strcmp(answer,"Three") == 0)
	{
		if (Dice== 3)
		{
			cout<<"You win!"<<endl;
			return 6;
		}
		else
		{
			cout<<"You lose!"<<endl;
			return 0;
		}
    }
	if(strcmp(answer,"Four") == 0)
	{
		if (Dice == 4)
		{
			cout<<"You  win!"<<endl;
			return 6;
		}
		else
		{
			cout<<"you lose!"<<endl;
			return 0;
		}
    }
	if(strcmp(answer,"Five") == 0)
	{
		if (Dice == 5)
		{
			cout<<"you win!"<<endl;
			return 6;
		}
		else
		{
			cout<<"you lose!"<<endl;
			return 0;
		}
    }
	if(strcmp(answer,"Six") == 0)
	{
		if (Dice == 6)
		{
			cout<<"You win!"<<endl;
			return 6;
		}
		else
		{
			cout<<"You lose!"<<endl;
			return 0;
		}
}

}

Recommended Answers

All 3 Replies

The program doesnot accept 'one' because it is not checked for winning even if 1 do comes in dice, you can solve it by using 'toupper' function for answer variable and checking for uppercase only, no matter what the user enters......
And I did not encountered the problem you mentioned, may be your compiler is outdated, I'd recommend CodeBlocks 10.05, it is free and very stable......this is unless you already use Visual c++ , which is good.....
And you also should try to use ANSI C++ ,

For std::string, I'd do it this way:

// case insensitive string compare function
int compare_string(const std::string & s1, const std::string& s2) {
    std::string::const_iterator it1=s1.begin();
    std::string::const_iterator it2=s2.begin();

    size_t size1=s1.size(), size2=s2.size();// cache lengths
    //return -1 or 1 according to strings' lengths
    if (size1!=size2) 
        return (size1<size2) ? -1 : 1;
    //stop when either string's end has been reached
    while ( (it1!=s1.end()) && (it2!=s2.end()) ) { 
        if(::toupper(*it1) != ::toupper(*it2)) // letters differ?
            // return -1 to indicate smaller than, 1 otherwise
            return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 
        //proceed to the next character in each string
        ++it1;
        ++it2;
    }
    return 0; // sizes and values equivalent
}

You'll have to modify it a little bit to accommodate an array of char

Good luck!

For std::string, I'd do it this way:

// case insensitive string compare function
int compare_string(const std::string & s1, const std::string& s2) {
    std::string::const_iterator it1=s1.begin();
    std::string::const_iterator it2=s2.begin();

    size_t size1=s1.size(), size2=s2.size();// cache lengths
    //return -1 or 1 according to strings' lengths
    if (size1!=size2) 
        return (size1<size2) ? -1 : 1;
    //stop when either string's end has been reached
    while ( (it1!=s1.end()) && (it2!=s2.end()) ) { 
        if(::toupper(*it1) != ::toupper(*it2)) // letters differ?
            // return -1 to indicate smaller than, 1 otherwise
            return (::toupper(*it1) < ::toupper(*it2)) ? -1 : 1; 
        //proceed to the next character in each string
        ++it1;
        ++it2;
    }
    return 0; // sizes and values equivalent
}

You'll have to modify it a little bit to accommodate an array of char

Good luck!

I dont understand how to think of these codes.
it is amazing.
I will modify to my program
thanks unimportant

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.