A dice game

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Fredde
    New Member
    • Sep 2010
    • 2

    #1

    A dice game

    Hi

    i'm creating a dice game where you start off to enter how many rolls you want and then you enter a player name and then the rolls occure. after that you will be able to enter an other name and when you want to finnish you are supposed to enter none as player name to get the text who won but i'm stuck after that i have entered the first name and the rolls occur and none works as well but i don't get the sum of th dice throws to work and i'm not sure what i should write when
    i want to show who has rolled highest
    Code:
    #include <iostream>
    #include <string>
    #include <iomanip>
    
    using namespace std;
    
    int main()
    {
    	string none="none";
    	string playername;
    	int dicethrow;
    	int howmany=0;
    	int sumofdicethrows=0;
    	
    	srand((int)time(NULL));
    	
    	cout<<"How many dice throws? "<<howmany;
    	cin>>howmany;
    	while(playername!=none)
    	{
    		cout<<"player name"<<playername;
    		cin>>playername;
    
    		if (playername==none)
    		{
    			cout<<"competition is over";
    		
    		}
    
    		else if (playername!=none)
    		{
    			for (int i=1; i<=howmany;i++)
    			{
    				dicethrow=rand()%6+1;
    				cout<<dicethrow<<"  ";
    				sumofdicethrows=dicethrow;
    				
    			}
    		}
    	}
    
    	return 0;
    }
    whould be greatful with some tips/help
    best regards fredde
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    It would be easier to help if you showed us the sections if your code causing problems.

    Comment

    • Fredde
      New Member
      • Sep 2010
      • 2

      #3
      so my code is posted

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        You might try using cin.getline instad of the cin >> operator to get your input string:

        Code:
        char buffer[80];
        cin.getline(buffer,80);
        playername = buffer;
        The cin >> stops on white space whereas the cin.getline fetches a named number of characters or until a \n is encountered.

        Comment

        Working...