C/C++ :: Dice Rolling - Keeping Track Of How Many Times A Number Appears?

Sep 27, 2014

I wrote a code that mimics a dice, my code so far will ask for the user to input a number at which they want to hold or no longer throw the dice, it will also ask the user how many roll simulations they would like to do.

If a 1 is rolled the turn is over and the score is 0

After this input is recieved the code goes into a loop until the values have been met.

I would to add probability to my code so I need to know how many times a certain number was rolled and this is where I am stuck.

An example of how I would like my code to work, let's suppose hold at number is 17

We role the dice until we roll a 17 or larger, but if we roll a 1, then our score is 0.

Let's suppose the number of simulations is 5 and for simulation 1 we roll

2 + 5 + 6 + 4 = 17

and for simulation 2 we roll

5 + 4 + 1, but since we rolled a 1, the score is 0,

for simulation 3 we roll

3 + 4 + 5 + 6 = 18

for simulation 4 we roll

4 + 4 + 6 + 6 = 20

for simulation 5 we roll

3 + 4 + 5 + 5 = 17 so that means we got

0: 1 time 1/5 = .20
17: 2 times 2/5 = .40
18: 1 time 1/5 = .20
19: 0 times 0/5 = .00
20: 1 time 1/5 = .20
21: 0 times 0/5 = .00
22: 0 times 0/5 = .00

In other words the idea is to roll a 17 or larger (or whatever the hold number happens to be), but if you roll a 1, then your score is a 0.

#include <iostream>
#include <cstdlib>
#include <ctime>
using std::cout;
using std::cin;
using std::endl;
int dieRoll();

[Code] ....

View 4 Replies


ADVERTISEMENT

C++ :: Search For A Number When Vector Is In Order - Count How Many Times That Number Appears

Feb 6, 2014

In this program what i'm doing is to search for a number when the vector is in order, and count how many times that number appears, the problem is that count how many times the number does not appear, but when its appear the program stays in an "standby mode" and the cursor does not move.

int buscarNumOrdenado (int x [MAX]) //MAX is the define {
int num,d, LimiteInferior, LimiteSuperior,mitad;
d=0;
LimiteInferior = 0;
LimiteSuperior = MAX-1;

[Code] ....

View 2 Replies View Related

C :: If Statements For Dice Rolling

Oct 9, 2014

I'm very new to C Programming and am doing some homework for my intro to C class. "There is a game where one can play and bet money on. Two dice are rolled and the numbers that appear on the dice are added together. If the total is 7 or 11, then the user wins. If the total is 2 or 12, then the user loses. If a different total appears. then the user gets their money back."

I have written the program below:

Code:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
int d1,d2,sum;
d1=0;
d2=0;
}

[code]...

However, after finishing the program, I realized that I NEEDED to use random numbers!!! How do I make my program generate random numbers within a range of 1-12? Also, how do I make my program generate NEW random numbers EVERY TIME instead of ONCE??

View 1 Replies View Related

C++ :: Random Generator For Dice Rolling?

Oct 29, 2013

How would you code a simple random generator for dice rolling?

View 2 Replies View Related

C++ :: Create A Dice Rolling Counter Using Classes?

Dec 1, 2014

I'm trying to create a program that rolls a dice a few thousand times and print out how many times it lands on each face and then print out a graph using x's as a visual representation using classes.

output looks like this:
1 --- 2000 xxxxxxxxxxxxxxxxxxxxxxxxx
2 --- 1950xxxxxxxxxxxxxxxxxxxxxxxx
.
.
6 --- 2050 xxxxxxxxxxxxxxxxxxxxxxxxxxx

I need a method called int count(int face) inside my class that returns the number of times a particular face has appeared, I just don't know how to incorporate this. I think I should use a constructor and destructor but i'm new with those and knowing when to actually use them.

Here is what I have so far that shows how it should look when printed, just struggling to convert using a class.

#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
using namespace std;

[Code]....

View 2 Replies View Related

C :: Program Where A Computer And Player Take Turns Rolling Dice

Feb 19, 2013

I am making a program where a computer and player take turns rolling dice.

There seems to be an issue somewhere in my loop where when the player selects from the possible dice choices, it rolls for the computer and does not select the choice and it immediately becomes the player's turn again.

I am trying to get it to where when the computer rolls the dice, it should display the list of possible values, and ask the user to hit the enter key in order for the computer to choose which value to select using the following command:

Code:
while ( getchar() != '
' ) ; I've tried it a hundred times and no matter where I put the command it still skips the computer's turn.

Below is my code:

Code:
while (compscore < 99 && playerscore < 99){
printf("You have rolled the following pair of dice:
");
a =("%i ", rand() % (MAX_VAL - MIN_VAL + 1) + MIN_VAL);
b =("%i ", rand() % (MAX_VAL - MIN_VAL + 1) + MIN_VAL);
multiply = a * b;

[Code] ....

View 11 Replies View Related

C/C++ :: Rolling Multiple Dice - Compare Total Sums

Feb 1, 2015

I am building the game risk and I want to start off with a dice rolling mechanism. In risk 5 die are needed so I want to know the most efficient way of churning out the code for this. Since the players have the options of rolling 1, 2 or 3 die (max 3 for attacker, and max 2 for defender) I was thinking something like this after searching the web for a few different options:

const int minNum = 1;
const int maxNum = 6;
int numberGenerator(){
int x;
x = minNum + rand() % (maxNum - minNum + 1);

[Code] ....

Since I will be asking the player the option to choose how many die to roll, is this the most efficient way? I want to compare the total sums after the die are rolled. If they choose 3 dice (the attacker) I will simply call the first 3 methods and either 1 or 2 for the defender.

View 14 Replies View Related

C++ :: Count How Many Times Each Word Appears - Empty Output Array File

Sep 20, 2014

I am writing this program that is supposed to read a file, put the data into an array, alphabetize, count how many times each word appears and print to an output function. I posted before on how my program had an error when I ran it but I have fixed that. Now my outputArray file is empty. It gets created but there's nothing in it.

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;
//global to this file

[Code] .....

View 3 Replies View Related

C :: Number 1 Appears In Next Line Every Time On Typing A Character

May 17, 2014

Everytime I type a character, the number 1 appears in the next line. And i just keep getting the message "Wrong! I have more than that." even when I type a number bigger than 1023

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void) {
srand(time(NULL));

[Code] ....

View 10 Replies View Related

C++ :: Random Number Generator - Count How Many Times Each Number Shows Up

Sep 26, 2012

I'm running a game online and designing a program to generate Enemy Stats. Basically, it's supposed to generate 25 numbers between 0 and 7(to represent 8 Attributes on a 25 Point Buy system) and count how many times each number shows up.

Here's what the code looks like:

Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int Generate() {
int r= rand();
int s= r%7;
[Code] ....

And here's two outputs.

1: Code:

12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 12133089220 Stats[0]= 25 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 0 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall

2: Code:

14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 14787708434 Stats[0]= 0 Stats[1]= 0 Stats[2]= 0 Stats[3]= 0 Stats[4]= 25 Stats[5]= 0 Stats[6]= 0 Stats[7]= 0 Stats[8]= 0 Disallowed system call: SYS_socketcall

Note that the number does change, but only between runs.

View 3 Replies View Related

C++ :: Dice (with Varying Number Of Sides) Program To Calculate Percentage Of Results

Oct 28, 2013

I am trying to code and compile a program that requests a uses to first inpu the number of sides they wish for a dice to have and secondly input the number of dice throws they would like to calculate the value for. The program will print an error message and default the number of sides the dice has to 5 if the number entered is below 4. Finally it will print out a percentage figure for each value that results from all the the dice rolls.

I have attached my header, driver and class files below along with accompanying error messages below them

// file name Exercise.cpp
#include <iostream>
#include "Die.h"
using namespace std;
int main() // the main program begins here
{
char restart = 'y'; // declare variables
double numRolls = 0.0;
int diceTot = 0;

[Code] .....

View 5 Replies View Related

C++ :: Loop A Set Number Of Times

Oct 29, 2013

I have been trying to make a program that asks for username and password, and if it is wrong it will loop back to the top. But i only want it to loop a set number of times, how can i do this? This is my code so far

string username;
string password;
cout << "Enter username: ";
getline(cin, username, '

[Code] ....

View 4 Replies View Related

C++ :: Program That Loops X Number Of Times

Feb 20, 2015

I'm trying to create a program that loops "x" number of times, where "x" is going to be a user-input number.

View 2 Replies View Related

C# :: List Number Of Times A Method Is Called

Mar 17, 2015

I want to write how many times a method is called. The first class houses a method that I want to count from the second class how many times it is called. what I am able to achieve so far is that it only writes out how many times it is called but what I want is that it should be like a counter like this: if called ofr 5 times it should print:

1
2
3
4
5
and not just 5.

First class

public static int count = 0;
public void Login(String LoginUsername, String LoginPassword) {
count++;
}
Second class
int i = LoginReusables.count;
i++;
System.IO.File.WriteAllText(@"C:Usersken4wardDesktopTidyWriteLines.txt", i.ToString());

View 11 Replies View Related

C :: Process For Printing Number Of Times A Switch Case Has Been Used?

Sep 20, 2013

I want to have one case of my switch statement to print out how many times the user has chosen other cases in the switch statement. Such as "You have pressed 2 6 times and 4 3 times."

View 3 Replies View Related

C++ :: Produce Normal Distribution Random Number Several Times

Aug 22, 2014

I wrote the following program shown below that produces a normally distributed random number several times, and then takes the average of them. The problem that I have been having though is that the output it has been producing is 0.0288385 despite the fact that I set the mean of the normal distribution to be 0.1. Why this output value would be so far off from 0.1 despite having averaged over such a large number of random numbers namely 10,000 of them? Also, how to randomly seed this random number generator such that it gives a different value each time its run perhaps by seeding it with the windows timer? Below is the program.

#include <iostream>
#include <random>
using namespace std;
int main() {
default_random_engine generator;
normal_distribution<double> distribution1(0.1,3.0);
double number1,sum,n;

[code].....

View 2 Replies View Related

C/C++ :: Counting Specific Amount Of Times A Number Shows Up

Apr 11, 2015

Ok, so I am writing this program with 10 different functions, and one of those functions needs to count how many times 0 appears in a text file. I've done this before, but I am so stumped right now. Should I get the numbers from the 2d array I have, or should I just use the text file here? Here is what I have right now:

int toursMissed(int scores[][COLS]){
int counter;
for(counter=0;counter<=96;counter++){
if(scores==0){
counter++;
return counter;
}
}

View 7 Replies View Related

C/C++ :: For Loop To Print Given Character Number Of Times Specified By Integer

Feb 11, 2014

The function uses a "for" loop to print the given character the number of times specified by the integer.

How can I make a for loop to do that?

So.. my code looks like this:

// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {

[Code] ....

So.. here is my error:

Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6

View 3 Replies View Related

C/C++ :: How To Store The Number Of Times User Input Received

Mar 15, 2015

I'm trying to write a function in C that calculates the average test score given by the user an arbitrary number of times...

View 14 Replies View Related

C++ :: Extracting From Loops - Run X Number Of Times And Produce A Prize Each Time

Sep 19, 2013

so i have a loop that will run x number of times and each time it will produce a prize which is a certain sum of money. I need to a way to sum all the money earned. I am thinking there should be a way to extract the prize one for each time the loop runs but i am not sure how to do that.

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

int main() {
cout <<"Option A: Drop one chip into one slot" << endl;

[Code] .....

View 2 Replies View Related

C++ :: Print Out Result Of One Number Being Added By Two Numbers 999999 Times

Feb 17, 2013

How would I by any means print out the result of one number being added by two numbers 999999 times, the numbers both happen to be about 16500 digits long. It must display ALL digits in the number (all the digits the result ends up being). I know I can't use normal data-types, so what do I do?

Looks kinda like this:

for (int i = 0; i < 999999; ++i)
{
total += a;
total += b;
}

a and b being 2 different numbers with about 16500 digits.

View 2 Replies View Related

C++ :: For Loop - Code Puts Out Switch Statement 5 Times With Random Number

Jan 26, 2014

I am writing for loop with a switch so that scores can be inputted in by a judge. The issue that I am running into is that I will put out an the text then the test happens and the code puts out the switch statement 5 times with random number. Here is what I have written.

Code:
int main() {
int diver;
int option;
int Judge;
cout << "Enter Divers Name:";

[Code] ....

View 4 Replies View Related

C++ :: Determine Number Of Times Change Each Specific Character In String To Make It Palindrome

Feb 19, 2015

I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.

Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.

I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.

int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;

[Code] ....

View 1 Replies View Related

C++ :: Keeping Output Window Open

Jun 24, 2014

My program accepts strings, places them in a vector and then "bleeps!" out words of my choosing, in this case, "broccoli". But I'm having trouble keeping the output window open even with my Keep_window_open() implementation.

#include "iostream"
#include "string"
#include "vector"
#include "algorithm"
#include "cmath"
using namespace std;

[code]....

View 2 Replies View Related

C++ :: Keeping A Listbox Loaded During Startup?

Jan 17, 2013

how is it done?

ex. mp3player keeps songs loaded

View 1 Replies View Related

C++ :: Structures - Keeping High Scores Of Users

Jun 1, 2013

Write a program that allows a user to enter high scores of a game, keeping tracking of the name of the user and the score. Add the ability to show the highest score for each user, all scores for a particular user, all scores from all users, and the list of users.

This is the program I am trying to write, however I am having difficulty storing the users name and high score, I know I need to store an array for the score but getting confused because of the structure. (By the way I have to use structures as it is a problem from the structures chapter of the ebook I am doing). Below is my code so far. .

Code:

#include <iostream>
#include <string>
using namespace std;
struct highScore
{
string user;
int score;
int highestScore;
int allScores;

[Code]...

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved