C :: Snakes And Ladder Program - Dice Function To Switch Between Players

Mar 25, 2013

I am writing a snakes and ladder program and I'm almost finished, but I am struggling with the dice to work in the way I want it to work. I want the dice to work like this :

Before each player throw the dice they must start at 0.
Each player must throw a 6 on the dice to move on the board.
If a player threw a 6 on the dice, that player can throw again.

But I ended up with two seperate dice, one for each player (game is only for two players).And when I run the program, both players don't start at 0. And when I throw the dice, both players move at the same time but with different values.

If one of my players threw a 6, they just keep on throwing until someone wins the game. I tried to use a switch and if statements but I couldn't get it right. And so I did this :

Code:
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#define SpaceBar 32// 32 is an ASCII value for a spacebar

[Code] ....

View 5 Replies


ADVERTISEMENT

C++ :: Program That Takes Baseball Players Statistics And Display Averages - Function Division

Oct 10, 2013

I was required to write a program that takes a baseball players statistics and displays there averages. I was required to make 3 function in the file to perform this tasks. my problem I am having a division problem in the SLG function. My compiler does not require the system ("PAUSE"); command.

OUTPUT
The player's batting average is: 0.347
The player's on-base percentage is: 0.375
The player's slugging percentage is:
(test)AB = 101
(test)Tot Base = 58
0.000

Code:
/* Batting Average Program
file: batavg1CPP.cpp
Glossary of abbreviations:
BA = batting average
PA = plate appearances
H = hits
BB = bases on balls (walks)

[Code] ....

View 3 Replies View Related

C/C++ :: Program To Calculate Stats Based On Snakes And Ladders

Feb 28, 2014

I have a problem with my code while trying to simulate a snakes and ladders program. The objective of the program is to simulate many games (100000+) to gain statistics:

1. The most likely number of rolls.
2. The mean value of the number of rolls.
3. The most common square, C, on which a token may come to rest. i.e. move on to.
4. The probability of coming to rest on square C.
5. The least likely square on which a token may come to rest and what is the probability of this occurring.
6. The distribution in the number of rolls needed per game presented as a normalised graph.
7. The minimum number of rolls of the die - called Nmin.
8. How many different paths (unique sequences of die rolls) take Nmin rolls to complete the game?

However my program (on Tenacious C) doesn't seem to run at all...

I have run it on internet compilers and other compilers but it must work on Tenacious C.

Below is the code I have at the moment, it works fine when stepped through or ran on a different compiler.

How to create code to answer the 8 points above. For instance, to get point number 2. I must find the total rolls divided by the total number of games, but am not sure how to do this.

Code:
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>
#define NUMBEROFGAMES 10
int GetThePositionOfMovement(int CurrentPosition, int dieValue);

[Code] .....

Attached image(s)

View 3 Replies View Related

C++ :: Program To Search Soccer Players Data To Check Whether Name Supplied By User Is On That List

Oct 29, 2014

Write a program that will search soccer players data to check whether a name supplied by the user is on that list. For doing the search, the user may provide either the player’s full last name or one or more starting letters of the last name. If a matching last name is found, the program will display the player’s full name and date of birth. Otherwise, it will display “Not found”.

Requirements specification:At the start, the program will ask the user to enter information about 10 soccer players constituting soccer player data. Each soccer player data will consist of the following fields:

Last name
First name
Birth month
Birth day
Birth year

The user will be asked to enter each soccer player data on a separate line with the field values separated by a space.

Once the data is entered, the program will display a menu of choices as below:

Chose an option:

(1 – input data, 2 – display original data, 3 – sort data , 4 – display sorted data 5 – search by last name 6 – exit the program )

If the user chooses option 1, the program will ask the user for a data and populate the array of structures that will hold the data for each of the soccer players.

If the user chooses option 2, the program will display data in the order provided by the user (original data).

If use chooses option 3, the program will sort data by last name.

If user chooses number 4 the program will display the data sorted by last name.

If the user chooses option 5, the program will ask the user to enter one or more starting letters of the soccer player’s last name. It will then search the soccer player data for the matching last name. If a match is found, it will display the first player found with the matching pattern. If a match is not found, the program will display “Not found”. If the user enters two forward slashes (//) for the last name, it will no longer search for the name. Instead it will display the main option menu.

If the user chooses option 6, the program will display “Thank you for using this program” and will end.

Why my program isint executing correctly. Here is what i've so far . . . .

#include <iostream>
#include <string>
using namespace std;
struct data {
string lname;
string fname;
int birthmonth;
int birthday;
int birthyear;

[Code]...

View 3 Replies View Related

C++ :: Sort Players In Descending Order On The Basis Of Score - Program Not Working Properly

Feb 11, 2015

#include <iostream.h>
#include <stdlib.h>
#include <time.h>
using namespace std;

class Player {
private:
char name[20];
int score;

[Code] .....

View 5 Replies View Related

C/C++ :: Sum Function Of For Loop For Dice Generator

Oct 15, 2014

I have written the code below that allows the user to input any sided dice and any number of rolls. The program will print out the output in sequence. I need to sum these outputs into one number, but I am having trouble writing a sum function for this.

//This Program Creates the Sum of a Number of Dice Rolls of the Same Size  

#include <stdio.h> 
#include <math.h>
#include <time.h> 
int rolldie();   
int main(){ 
int x, n, a; //'x' n=number of rolls, a=number sided dice

[Code] ....

The output looks something like this currently:

Please Enter the Number Sided Dice Followed by the number of Rolls... 12 10
4 12 2 10 12 5 5 12 12 5 >Exit code: 0

View 2 Replies View Related

C :: Simulate Roll Of A Dice - How To Use Rand Function

Sep 23, 2014

I saw a program in which it uses rand like this:-

d1=rand() % 6+ 1;

where, d1 is any integer. The program is to simulate the roll of a dice. The whole program is this:-

Code:

#include<stdio.h>
#include<stdlib.h>
main() {
int i;
int d1, d2;
int a[13];

[Code] .....

View 10 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

Visual C++ :: Dice Game - Creating Pass By Value Function Reference

Nov 27, 2014

i have a project where i create a dice game, the user rolls 2 dice and the computer roles 2 dice. the player that wins 3 out of 5 rolls wins the game. I have completed the requirements, but i wanted to create a pass by value function for "void Dice()", I'm not too sure how that works?

Code:

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
//creating my variables and their values
int compinput;

[Code] .....

View 5 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++ :: Dice Game - Receive Same Values When Roll Function Get Call Twice For Same Object

Nov 7, 2013

#include <iostream>
#include <cstdlib>
#include <time.h>
#include <conio.h>
using namespace std;
class Dice {

[Code] ....

Every time the roll_dice function get call twice for the same object, i receive the same dice values.

View 4 Replies View Related

C/C++ :: Snakes And Ladders Codeblocks Error

May 5, 2014

My error on code blocks is fatal error no such file found in iostream, I don't understand this error!!

#include <iostream>
#include <cstdlib>
#include <string>
#include <ctime>
#include <fstream>
#include <vector>
#include <sstream>
#include <iterator>
int Random(int random) {
return (rand() % random) + 1;

[Code] .....

View 7 Replies View Related

C/C++ :: Program Closes When Using Any Number In Switch

Feb 17, 2015

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code]....

when running the program it closses after the switch.

View 2 Replies View Related

C/C++ :: How To Use Switch Statement 2 Times In A Program

May 10, 2012

How can we use switch statement 2 times in a program?

View 2 Replies View Related

C/C++ :: How To Put All Questions In One Program By Using Switch Statement

Mar 22, 2013

How to put my all assignment questions that are 6 in number in one program by using switch statement ?

so if a user wants to see any question by choice!

View 1 Replies View Related

C++ :: How To Pass Function Return From Switch

Aug 23, 2013

How to do i fix this code im not good at using function, im trying to pass a statement from switch to my double passengersR i always come out with a error

this output:
Name passenger:
Enter number passenger:
Choose from A to D
if choose A
Total Regular Passenger: 6.19624e-312

did i do something wrong im not really good at function and im trying to learn how to pass switch to void function

Code:

#include<conio.h>
#include <iostream>
#include <Iomanip>
#include <string>
using namespace std;
double passengersR ()
{ double m;

[Code]...

View 4 Replies View Related

C++ :: Passing A Function Value Into Switch Statement

Feb 23, 2015

I had it working with the switch statement within the function, but later instructions said that it must be inside of main. I just get a loop no matter what I do. 5 needs to exit the program, all the other selections need to display the corresponding cout statements. I've done something to where the inputs are not actually passing into the switch statement. If any value other than 1-5 is put in, the menu should repeat and prompt the user again.

#include <iostream>
#include <cmath>
#include <cstdlib>

using namespace std;
int call_menu(int selection);
double kilo_m(double miles);

[Code] .....

View 2 Replies View Related

C :: Use Switch Case As A Menu To Switch Between Patients

Dec 30, 2014

I am trying to make a program which manages the data of 5 different patients (its an uni assignment), and i want to use a switch case as a menu to switch between the patients. All other functions (as for example putting the infromation on a file) work, but i cant figure out to bring the switch to work. First it asks for the number of the patient which should be worked with, this works perfectly, but afterwards changiung between the persons doesnt work as thought. It should ask everytime after it switches to one patient (i removed some functions to make it easier to read) and then asks to which it should jump next. If i put the number of one case (lets say 3) it just stops the program.

********Example:
user@pc ~/wherever $ ./program
current variables:
jo = 2
a = 0
1 //the entered number
The variable a = 1
patient 1
Enter the number of the next patient2
// and then it closes
**************

The same thing happens if i compile an example code from a book, it writes the first case and then stops.

I looked already through the forum but didnt find a person with a similar problem, maybe i didnt dig deep enough.

I am running Linux Mint 17 and use gcc as compiler.

Code:

include <stdio.h>
#include <stdlib.h>
int a=0;
int jo=2;
int main(void){
printf("current variables:
jo = %d
a = %d

[Code]...

View 13 Replies View Related

C :: Blackjack Program - Multiple Choices In Switch

Dec 6, 2014

I'm writing a Blackjack program where the user can choose to Hit(H) or Stand (S). I would like them to be able to use upper or lower case letter for this. My code doesn't seem to work right for my Stands.

Code:
char choice;
do {
choice = 0;
while (choice < 1) {
printf("

[Code] ....

View 3 Replies View Related

C++ :: Menu Program As Switch-Case Structure

Feb 13, 2015

I tried to write a menu program as a switch-case structure with a separate function for a switch-case structure itself. The outcome for it currently is an undesired one

Code:

#include <iostream>
using namespace std;
int menu(int answer);
int main()

[Code].....

The output I get is one where it's just an infinite loop of "Bad choice! Please try again later.".

View 7 Replies View Related

C++ :: Write A Program That Has A Menu With A Switch Statement?

May 4, 2014

I'm trying to write a program that has a menu with a switch statement. I'm getting "case label'1' not within a switch statement" and subsequent errors for the other two choices and the default.

int main(){
int choice;
Matrix A,B,C;
cout <<"What would you like to do? "<< endl;

[Code]....

View 2 Replies View Related

C++ :: Switch Structures - Program To Arrange Values

Mar 5, 2012

Write a program that accepts three values (int) from the keyboard into three variables a, b and c. After loading the variables, your program will arrange the values into a, b, and c, so that a contains the larger, be the next and c the smallest.

You can use any other variables in addition to a, b c, as you see fit.

You will have to use some variation(s) of the if construct.

There are many ways to program this, but your challenge will be to achieve this without doing all possible comparisons. In fact, three comparisons woudl be enough, if you , for example, determine the largest number first, and keep track of its position in some way , so you can compare the other two.

I think I might use a code similar to the one below.

switch (expression) {
case constant1:
group of statements 1;
break;
case constant2:

[Code] ....

View 14 Replies View Related

C++ :: How To Test Multiple Boolean Using A Switch Function

Oct 21, 2013

I don't know that a Function is the right word for switch/case but it seems like this would exist, is there a way to test multiple booleans using a switch function?

View 1 Replies View Related

C++ :: Switch Case - Program That Calculates Students Grade

Apr 18, 2013

Trying to write a program that calculates a students grade based on how many assignments have been graded. I am using a switch case since there is a total of 5 assignments, however when I enter case 1, and enter in how many I got out of 100, it just closes the program it doesn't go to the next part.

#include <iostream>
using namespace std;
char calculategrade(int total);
int main() {
// local variable declaration:
char input;

[Code]....

View 6 Replies View Related

C++ :: Program Using Switch Statements To Pass Multiple Functions

Oct 1, 2014

I am returning area from areaCircle(), but do not know how to print it in main. I know this program has lots of errors, two cases that I have listed.

Not sure how to properly list multiple function calls in a switch statement, and how to print one's return from main.

int main() {
char choice;
double area;
showMenu(choice);
switch (choice) // If input is C, use getRadius, areaCircle and count, then print the are
{
case 'C': void getRadius(),double areaCircle(), void count(bool display = false);

[Code]...

View 5 Replies View Related

C++ :: Using Rand Function In While Loop And Output Using Switch Statement

Jun 12, 2014

Basically I'm supposed to use a while loop to generate a random number and use a switch statement to output the appropriate information. I feel like I'm missing a few things that are very simple.

The errors are:
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4700: uninitialized local variable 'randomNumber' used

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

using namespace std;
int main(){
int i = 0;
unsigned int randomNumber;

[Code] .....

View 2 Replies View Related







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