C++ :: Adding Up Values Of Dice Rolls In A While Loop

Feb 19, 2013

I'm having a problem adding up the values of the dice rolls in a while loop. The program will only store the last value so how would I get it to store multiples values? Here is my program thus far. I would try an array but we haven't gotten to that yet.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int die_1=0, die_2=0, total_score1, total_score2, player1score;
char enter;

[Code] ....

What operators or equation I should use to accomplish this?

View 7 Replies


ADVERTISEMENT

C++ :: Five Dice Roll - Read Out Average And Sum Of Rolls

Feb 7, 2013

My issue is that my program dies whenever it attempts to readout the average and sum of the rolls. I think I need to include the size function in here somewhere but am not sure how to go about it. Possibly scrap the "do while" loop and go with something else, or just am completely missing something.

Here's the code:

#include<iostream>
#include<random>
#include<ctime>
#include<vector>
#include<cstdlib>
#include<iomanip>
using namespace std;
int sum5(int d1, int d2, int d3, int d4, int d5);
int DiceRoll();

[Code] ....

View 3 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++ :: 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++ :: Adding Reciprocals Of The Numbers From 1 To 10 - Loop

May 2, 2014

How to do the problem below using loop?

Using loop...

Output the total of the reciprocals of the numbers from 1 to 10:

1/1 + 1/2 + 1/3 + 1/4 ... + 1/10 = 2.928968

View 3 Replies View Related

C# :: Store Data In Memory After Adding Values

Oct 23, 2014

I serialize a XML file, and i have this values here:

public class ServiceConfig {
public List<DatabaseDescriptor> Databases { get; set; }
} public class DatabaseDescriptor {
[XmlElement("Name")]

[Code] ....

I have a form1 which is a datagrid view and get's updated like this:

dataGridView1.DataSource = xmlData.Databases;

Now i have a button: get tables, and it opens up form 2, there it's supposed to appear all the tables of the selected Database, when i click on the row i get the database name so i get all the list of Tables from

DatabaseDescriptor
where
DatabaseDescriptor.Name == name
(I get this when i select the row)

But then on the 2nd form, i also have 2 textbox so i add a new table, i add the tablename and id. the new value should appear in the datagridview of the tables, and when i close it and reopen it, it should be there. Maybe i should concatenate first the values or something, how do i do?

View 3 Replies View Related

C/C++ :: DiceRoller Not Printing Rolls

Apr 7, 2015

#include <stdio.h>
#include <cstdlib>
#include <ctime>

[Code].....

Why is it this does not print out the number?

The goal is to print 10 groups of 5 rolls per group, can't figure this out...

View 10 Replies View Related

C++ :: Code For Digital Clock - Adding While Loop?

Aug 23, 2013

This is my code for a digital clock. It only refreshes when i type in a letter.

#include <iostream>
#include <ctime>
#include <iomanip>
using namespace std;
//char dateStr [9];
char timeStr [9];
char almtimestr[9];

[code]....

View 3 Replies View Related

C :: Create ASCII Bar Graph Of Die Rolls

May 24, 2013

for an assignment we need to create basically a program that asks the user for the result of standard six-sided die rolls (numbers from 1 to 6). The program will prompt the user with "Enter a die roll or 0 to exit " for the first entry and Next die roll? for all subsequent entries. The program will continue reading die rolls from the user until the user enters 0. At this point, the program prints two newline characters (one blank line) and finally, the bar chart showing the number of times each die roll has been entered, and then terminates.If the user enters an invalid number, the program will just ignore it, and ask for another number. Only numbers 1-6 inclusive and 0 are valid.

Example output Enter a die roll or 0 to exit 6 Next die roll? 6 Next die roll? 7 Next die roll? 4 Next die roll? 0

[code].....

View 3 Replies View Related

C# :: Fibonacci Series - Adding Value In Array Inside While Loop

May 27, 2014

I am making a program to run Fibonacci series. I have created 2 array.

1)- 1st array holds only 0, 1
2)- 2nd array holds other values eg: 1, 2, 3, 5..........etc

I am using while loop to get the febonacci series and storing it in a 2nd array called int[] numbers.

After getting value using while loop, I am joing both the arrays using int[] final = arr.Concat(number).ToArray();

At last, I have used foreach loop to add the febonacci series into the listbox.

The problem I have is that, I cannot able to concat both the arrays. I tried to assign number array at the top of the while loop. so that number variable will be accessible outside the while loop. But I am getting a error.

See the code below

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

[Code] .....

View 4 Replies View Related

C/C++ :: Expected Outcome Error On X Amount Of Rolls

Feb 20, 2015

I have a program that rolls two dice however many times the user specifies and counts the occurrences of each total (2-12). I have to compare the results of the random rolls to the expected outcome and give the percentage of error between the two.

I have an example that tells me the sum to expected outcome are as follows if I roll 36 times: 2/1, 3/2, 4/3, 5/4, 6/5, 7/6, 8/5, 9/4, 10/3, 11/2, 12/1 but I don't know how to put that into code to get the expected outcome for X amount of rolls.

View 11 Replies View Related

C++ :: How To Add Values Of For Loop

Feb 9, 2014

I want to add each of the values that are calculated by the end of each for loop.

For example:

for(int i = 0; i < 10; i++)
{
int x;
}

I want to be able to add all of the x values calculated from the for loop together. How to do that?

View 6 Replies View Related

C :: Returning Values From While Loop

Jul 13, 2013

I am currently doing a bodyfat calculator for a course in school.I'm having a problem getting an output returned from my while loop, which determines the user's gender by user input.My function (outside of main) is currently:

Code:

char gendercheck(gender){
while (true) {
gender = _getch();
if (gender == 'M' || gender == 'm') {
system("cls");
printf("Your selected gender is male.");
break ;

[code]....

My failed tries include "return gender" and "return genderpicked" statements in both the if-functions and the loop itself, which I have deleted since that didn't work. My goal is to get a character stored in gender, so that I can use the information of the user's gender in my main function from this point and onwards.

MY MAIN IS:

Code:

int main() {
char *genderpicked ;
char gender ;
genderpicked = &gender ;

[code]....

View 9 Replies View Related

C++ :: How To Total The Values That Are Put In During The Loop

Oct 23, 2014

How to total the values that are put in during the loop. For this program I need to add up the values the user inputs and then display them after the loop. Here is what I have:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
const int firstQuiz = 1, lastQuiz = 4;
int quiz, quizGrade;
for (quiz = firstQuiz; quiz <= lastQuiz; quiz++)

[code]...

View 4 Replies View Related

C++ :: Function Returns Values After Loop Done

May 15, 2013

I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:

int goC(){
... // some local value definition
for(int i = 0; i < 1000; i++){
... // a lot of calculations done here
return i; // -> return the value after each loop is done
}
}

Here it only returns one value, i = 0. Clearly it's wrong.

View 10 Replies View Related

C/C++ :: Loop Not Comparing Values Correctly?

May 12, 2014

So, I have the beginnings of a rock paper scissors game which i have created before in Java, and i am attempting to create it in c++.

Problem is, the function "int checkConvertInput" containing a loop to make sure input is valid, is not exiting the loop. As far as i can see the two strings are not comparing. Is there a library function for this? I know C had strcmp but i am not sure if it applies here.

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int checkConvertInput(int playerSign, string signs[]);

[Code] ....

View 6 Replies View Related

C/C++ :: Storing Values In Arrays Using For Loop

Nov 18, 2013

I am trying to create a program that will give me an value for a chosen from the user array ut I believe the program I've made does not recognize the values of the previous arrays. (Here is my program):

#include<stdio.h>
int main() {
int n;
int i;
int j;
float c;
float a[10000];

[Code] ....

There must be problem cause every value I give n(only for n=1 the answer is correct) the result is "a[n] is -inf"

View 1 Replies View Related

C++ :: Using For Loop To Input And Output Array Values

Jan 23, 2014

so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values

*/
#include <stdio.h>
int main(void) {
/* Declare an array of integers */
int Grades[5];
int nCount;
/* Populate the array */
for(nCount = 0; nCount < 5; nCount++)

[Code]...

View 3 Replies View Related

C/C++ :: Finding Sum Of Values Entered By User In While-loop?

Aug 26, 2014

Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered. When the loop ends, print the smallest, the largest, the number of values,and the sum of values. Note that to keep the sum, you have to decide on a unit to use for that sum; use cm.

View 9 Replies View Related

C++ :: Passing Values Into Array Using For Loop From Input File

Jul 5, 2014

I'm trying to pass these numbers into the array using the for loop: 1, 2, 3, 4, 5. I created two files in my project called "inStuff.txt" and "OUTPUTS.txt". I know I have an error at my input in the for loop, which is a bit similar to my problem or something? I'm also on linux using a crossGCC complier(not sure if that makes a difference).

#include <iostream>
#include <fstream>
using namespace std;

[Code]....

View 4 Replies View Related

C++ :: For Loop To Find Index Values - Reference List

Mar 18, 2013

im using a for loop to find the index values of the tied high scores and store them into string list then reference list in the second for loop to output it to screen however it isnt letting me use an array with index i as an index its self.

void printHighest(Student s[], int length){
int index;
string list[10];//you're never going to have more than 10 people with a tieing highscore.
index = findMax(s, length);

[Code] ....

For the time being I simply removed the idea of string list and just put the contents of the second for loop into the if statement above it. However, I am still curious as to if I can reference an index of an array in an index of another array.

View 1 Replies View Related

C++ :: Finding Maximum And Minimum Values Of 10 Numbers Using For Loop

Jan 22, 2013

I want to finding maximum and minimum values of 10 numbers using for loop and the program work wrong !!

#include <iostream>
using namespace std;
int main() {
int x;
int max = -999999999;
int min= 999999999;

[Code] ....

View 2 Replies View Related

C++ :: Loop Program To Go Back Without Losing Values Of Variables?

Mar 30, 2014

I know that returning to main() is not a good idea but how will I loop the program to go back to the position selection when the voter is done voting for the last position.

when I run the program it seems fine. getting the votes from President to PRO Position is fine. The problem is how will the next voter vote without losing the vote (tally) of the previous voter?

FLOW:
SELECT POSITION (a-e) ---> SELECT A CANDIDATE (a-c) ---> (this goes on until the position of PRO) ---> ( then go back to the POSITION SELECTION)

After every vote there is a case statement for which I can choose to vote for the next position, quit, or show results (and after showing the results it will go to the next position to vote)....

#include<iostream>
#include<string>
#include <conio.h>
using namespace std;
int pca=0,pcb=0,pcc=0,ptv=0;

[Code] .....

View 1 Replies View Related

C Sharp :: How To Loop Through Array List For Unique Values

Aug 19, 2012

I am grabbing data from three entities and want to grab a field value in each of the entites and place it in an arraylist. What I would like to do is loop through the arraylist for all the values and do something for each value only once. If the value in the array list is repeated, I want to not do anything for it and continue till the end. Basically, I loop through all the values do something for each value and skip over the repeated value if I already did something.

View 1 Replies View Related

C++ :: Using A For Loop To Input And Output Array Values Also Calculate The Average

Jan 24, 2014

I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average

*/
#include <stdio.h>
int main(void)
{
/* Declare an array of integers */
int Grades[5];
int nCount;
int nTotal = 0; /* Declare and initialise the value */
float fAverage;

[Code]...

View 1 Replies View Related

C++ :: Initializing Loop And Returning Values Rock Paper Scissors

Dec 2, 2013

When i return 0; at the function int userselect (int user, int comp)my output displays twice and when i ask the user to run it again the computers selection of rock, paper or scissors remains the same it doesn't find a new random number. So i made the function userselect return to main(). This works and my output is displayed once, but when i run it it skips my while part of my do while loop completely so it loops the program without asking the user if they wish to run it again.

but when i return main() the computers choice re-randomizes every time so i need to find a way to get the while part of my do while to initialize and the program to not loop without the option of ending it.

#include <iostream>
#include <string>
#include <cmath>

[Code]....

View 1 Replies View Related







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