C++ :: Program That Loops X Number Of Times
Feb 20, 2015I'm trying to create a program that loops "x" number of times, where "x" is going to be a user-input number.
View 2 RepliesI'm trying to create a program that loops "x" number of times, where "x" is going to be a user-input number.
View 2 Repliesso 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] .....
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] ....
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.
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] ....
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());
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 RelatedI 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].....
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;
}
}
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
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 RelatedHow 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.
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] ....
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] ....
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] ....
how would I write a while() loop that calculates the sum of all prime numbers from 1 - 50.
View 5 Replies View RelatedI want to create a specific number of for loops each in another loop, as in example:
for(i=0;i<9;i++)
{
for(j=0;j<9;j++)
{
for(k=0;k<9;k++)
{
//some stuff
}
}
}
In this example there are 3 loops, but what if i want to create e.g. 10 such loops, and program reads a number of loops from a txt? It is needed for checking numbers.
How can we use switch statement 2 times in a program?
View 2 Replies View RelatedI need to make a program which solove difference between two interested times in format hh:mm i made it but it doesn't give me right answers for all times for example it can't solve times like 23:50 and 0:15 and it says that difference is 23:35 and no 00:25
View 3 Replies View RelatedRepeat the vowel Problem 3 (0 / 0)Write a program that will repeat k times each single occurrence of a vowel in the input file "sp.txt" to a new file "output.txt". The first line of the input file contains only the parameter k. The first line (containing the parameter k) should not to be written in the output file.
I wrote the code but i cant figure out something. i read the file, i found the vowels but then i cant print them.
Code:
#include <stdio.h>#include <string.h>
#include <ctype.h>
#define MAX 100
int checkvowel(char c)
[Code].....
I'm having trouble getting my loop to work correctly. If I iterate the for loop once it works as expected and displays proper output. When I try to iterate two times or more the program gets stuck in an infinite loop.
testData8.dat:
Code:
12 9
13 756
I have to make my program display days 1-30 along side numbers increasing by 5 each day beginning with 6 on the first day. I wrote 2 for loops on separate tabs but now I want to know if its possible to combine them into 1.
For loop 1
int day,;
for (day = 1; day <=30; day = day + 1)
For loop 2
int candy;
for (int candy = 6; candy <=151; candy = candy +5)
What I am trying do is this in steps,
1)I took an integer
2)I try to convert it into binary by storing the remainder by dividing it in 2, in an integer array size of 8(array1)
3)But the digits are in the reverse order, so I reverse them(array 2)
4)When the number is less like 40 or 20 there are no 8 digits/bits
5)So further manipulation of bits i need to pad some other value(say its 2)in the beginning of the array where you
will have continuous zero bits.
for(k=0;k<8;k++) {
remZ=devZ%2;
devZ=(devZ-remZ)/2;
z_bit_array[k]=remZ;
[Code] .....
I want to pad another bit apart from 1 and 0 until you find one. for example say the content of array2 will be 00010111 then i need it to be 22210111.But my method is not working and make the program non responsive.
I just started learning the basics of programming. While encountering one of the practice problems in the book by Alex Allain I got a little confused. The question is as follows:
Write a menu program that lets the user select from a list of options, and if the input is not one of the options, reprint the list.
The author assumes you can answer this question only using if statements and/or loops (while, for and do).
This is the code I've written thus far:
Code: #include <iostream>
using namespace std;
int main()
{
int option;
char reset;
[Code] ....
For some reason, the nested while loop keeps repeating even when you input a valid option (1, 2 or 3). I can't seem to figure out why this happens.
I am trying to use enumeration types in my conditions to make a simple program that calculates area of a square or circle depending on users choice then updates the total area and outputs the total area.
The program builds fine. But it ignores all of my loop conditions and i'm not sure why.
Code:
#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <conio.h>
#include <fstream>
#include <string>
using namespace std;
[Code] ....
So i have to use these prototype functions to run loops and to pause the program, the only problem is after i select a loop option and enter a number of dots to print in the loop it goes into an infinite loop and why, also when i try using the 4 option to exit it still asks me how many dots i want to print.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int pause(char *);
int getInt(char *);
void whileFunction(int);
void doWhileFunction(int);
void forFunction(int);
[Code] .....