473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

A dice game

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
3 2662
Banfa
9,065 Expert Mod 8TB
It would be easier to help if you showed us the sections if your code causing problems.
Sep 15 '10 #2
Fredde
2
so my code is posted
Sep 15 '10 #3
weaknessforcats
9,208 Expert Mod 8TB
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

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

Similar topics

101
by: Elijah Cardon | last post by:
Let's say I have m dice having n sides, such that n^m is not going to bust int as a datatype. With m=4 and n=6, an outcome might be {2, 5, 1, 2}. What is a good way to represent this in c so that...
0
by: Bree | last post by:
The game requires it not to accept negative numbers. At the moment it isnt, and it is urgent I find the solution asap. So if anyone can help I would much appreciate it. Thanks Bree This is the...
1
by: lenest | last post by:
I need help writing a program.... You are to write a python program to accomplish the following: a.. Play a dice game of Craps using a random number generator to simulate the roll of the...
3
by: whitehatmiracle | last post by:
SOS When i comile this program, im getting 13 errors all saying "prompt_for_bet and get_bet are not memebers of class Player" Where am i going wrong? Can anyone plzz enlighten me? Thnking u...
1
by: Shark2026 | last post by:
Hi there I need to make a Craps game for my class. Here are the parameters for it. In the game of craps, a pass line bet proceeds as follows. Two six-sided dice are rolled; the first roll of the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.