By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

A dice game

P: 2
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
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     string none="none";
  10.     string playername;
  11.     int dicethrow;
  12.     int howmany=0;
  13.     int sumofdicethrows=0;
  14.  
  15.     srand((int)time(NULL));
  16.  
  17.     cout<<"How many dice throws? "<<howmany;
  18.     cin>>howmany;
  19.     while(playername!=none)
  20.     {
  21.         cout<<"player name"<<playername;
  22.         cin>>playername;
  23.  
  24.         if (playername==none)
  25.         {
  26.             cout<<"competition is over";
  27.  
  28.         }
  29.  
  30.         else if (playername!=none)
  31.         {
  32.             for (int i=1; i<=howmany;i++)
  33.             {
  34.                 dicethrow=rand()%6+1;
  35.                 cout<<dicethrow<<"  ";
  36.                 sumofdicethrows=dicethrow;
  37.  
  38.             }
  39.         }
  40.     }
  41.  
  42.     return 0;
  43. }
  44.  
whould be greatful with some tips/help
best regards fredde
Sep 15 '10 #1
Share this Question
Share on Google+
3 Replies


Banfa
Expert Mod 5K+
P: 8,916
It would be easier to help if you showed us the sections if your code causing problems.
Sep 15 '10 #2

P: 2
so my code is posted
Sep 15 '10 #3

weaknessforcats
Expert Mod 5K+
P: 9,197
You might try using cin.getline instad of the cin >> operator to get your input string:

Expand|Select|Wrap|Line Numbers
  1. char buffer[80];
  2. cin.getline(buffer,80);
  3. playername = buffer;
The cin >> stops on white space whereas the cin.getline fetches a named number of characters or until a \n is encountered.
Sep 16 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.