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


ADVERTISEMENT

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 :: 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 Sharp :: Unreachable Code Detected When Adding Switch Statement

Oct 28, 2013

I am getting an error "Unreachable code detected" when I add a switch statement.

My code looks like:

private void calbtn_click(object sender, EventArgs e) {
  double regFee;
  double lodging;
  double days;
  string Total  {
    string course;

[Code] ....

(Everything works functionally until I try to add the switch statement.)

View 2 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++ :: 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

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++ :: 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# :: Infinite Loop Random Boolean Print Statement

Feb 19, 2014

I am working on a small simple program my program fills up a air plane with customers there is 2 levels 1 and 2 and it will put that person in the spot depending on being picked.

So far i made a boolean airplane with 10 spots I can enter 1 person into the airplane with no problem but then after he sits down i get a infinite loop? I assume i maybe have to use the continue statement I feel like there is something simple that im missing i want to add more people. here is what i have

class Program
{
static void Main(string[] args)
{ bool[] planeSeats = {false, false, false, false, false, false, false, false, false, false };

[Code]......

View 1 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 :: Break Statement In Random Number Sorting

Jul 4, 2014

The program I am stuck on is used to generate random numbers, then sort them (found in Chapter 23, p. 212). When I compile it, I get an error stating "break statement not within loop or switch. I'm finding that there is an issue with a break statement, but I don't know enough yet.

Code:
/* Will generate random numbers, then sort them.*/

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

main() {
int ctr, inner, outer, didSwap, temp;
int nums[10];
time_t t;

[Code] ....

View 4 Replies View Related

C++ :: Create Random Number As Zip Code

Nov 21, 2014

I am trying to create a zipcode I write my code like that and it only show "-2" on the screen what happen to my code I can not find mistake!

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <ctime>
using namespace std;
class Zipcode {

[Code] ....

View 1 Replies View Related

C++ :: Random Number Generation In A Loop

Jan 2, 2014

I've researched this quite a bit and the overwhelming answer I've been seeing for a loop generating the same pseudo-random number is that you're seeing the random number generator inside the loop, but that is not the case with me . . . At least not that I can see.

Basically, as I mentioned, I have a loop "birthing" new bunnies in a loop. And all the new bunnies are being created with the same name and other details.

Here is the code:

void BunnyGraduation::breed() {
for (unsigned int male = 0; male < colony.size(); male++) {
if (colony.at(male).getSex() == Bunny::Sex::MALE && colony.at(male).getRadioactiveMutantVampireBunny() != true && colony.at(male).getAge() >= AGEOFCONSENT) {
for (unsigned int female = 0; female < colony.size(); female++) {

[Code] ....

srand(time(0)); is seeded ONCE in the constructor of the bunny object itself. . . Now, come to think of it, the constructor is called every time an object is created . . . And the constructor contains the srand() . . . and the constructor is being called in a loop. . . So therefore, yes, the srand() is being called inside the loop.

View 2 Replies View Related

C++ :: Transfer If-else Statement Into Switch Statement?

Sep 7, 2013

How to make if else code below into SWITCH STATEMENT?

cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;

[Code]....

View 6 Replies View Related

C :: Random Number Generator Inside / Outside A Loop?

Nov 15, 2013

I've been working on a program on and off for around a week now and I've been struggling towards the end of the program.First of all, the program is a maths quiz which generates two random numbers per question.I'll give you one part of my code:

Code:

srand ( time(NULL) ); //seeds the random number generator
int score = 0;
int a = rand()%12 +1; //generates a random num between 1-12
int b = rand()%12 +1;
int c = a+b;
int d;
}

[code]....

I've basically copied the above code 10 times and changed the variables by going through the alphabet e.g.

Code:

int a = rand()%12 +1; //generates a random num between 1-12
int b = rand()%12 +1;
int c = a+b;
int d; all the way to

Code:

int an = rand()%12 +1;
int ao = rand()%12 +1;
int ap = rand()%12 +1;
int aq = an+ao-ap;
int ar;

Now what I'm going to do is remove all the declared variables and create a loop. But my problem is; If I wanted to declare four variables for e.g.

Code:

int a = rand()%12 +1;
int b = rand()%12 +1;
int c = rand()%12 +1;
int d = a+b-c;

Would I place the srand( time(NULL)); inside the loop? it's confusing because I know an example of a basic loop with an array would be:

Code:

#include <stdio.h>
#include <conio.h>
int main(void)
{

int test[5]={21,18,47,21,4};
int I;
int total=0;

for (I=0;i<5;i++)
total += test[I];
}

[code]....

how or where to include the random number generator in the loop and to make it ask 10 questions at random.

View 1 Replies View Related

C++ :: Program To Generate Random Number Between 1 To 100 - While Loop Will Not End

Feb 21, 2014

My program asks me to write a C++ program that generates a random number between 1-100, and lets the user guess the number until he/she guesses correctly.

I have every thing done but my loop will not end. I know I have to "update" the loop to end it but I don't know what that means.

#include <iostream>
#include <iomanip>
#include <ctime>
using namespace std;

int main() {
srand(time(NULL)); //the function that generates random numbers

[Code] .....

View 2 Replies View Related

C/C++ :: How To Execute For Loop And Generate A Random Number

Oct 24, 2014

I have to write a C++ program that picks a random number between 0 and 49. If the number is even lets say 30, then the computer will display 30, 32, 34, 36... all the way till 100, if its odd lets say 17, then the computer will display 17, 19.. till 99. I got the computer picking a random number, I just can't figure out how to display every other number using a for loop statement. Here's my code for random number generator:
   
#include <iostream>
#include <cstdlib> 
#include <ctime>  
using namespace std;  
int main()  

[Code] ....   

View 4 Replies View Related

C++ :: From If Else To Switch Statement

Mar 6, 2013

I was wondering how you would put this if else statement to a switch statement.

void PlayerDB::AddPlayer(const Player& avatarPlayer) {
char * playerName = new char[avatarPlayer.lenName()];
Player*player = NULL;

[Code] ....

View 1 Replies View Related

C++ :: Switch Statement Is Not Working?

Aug 16, 2014

okay so like case 2 and 3 is not working, also the program is still not finish but why isn't case 2 and 3 not functioning well on the switch part? case 1 works just fine

Code:
#include<stdio.h>
main ()
{
//passcode part (passcode is 1234)

[Code].....

View 5 Replies View Related

C :: Switch Statement Array

Apr 15, 2014

so I am trying to have an switch statement array. but every time i complete a case statement the whole process is returned. the thing is i want the menu to stay up even if i complete the case.

View 2 Replies View Related

C++ :: How To Link A Switch Statement To A If / Else

Aug 8, 2014

The sample output of this program would be:

Please select:
1 - Year
2 - Day
3 - Month
Input choice: 1
Input Number: 2
I'm a Sophomore!

Please select:
1 - Year
2 - Day
3 - Month
Input choice: 2
Input Number: 2
It's Tuesday.

Please select:
1 - Year
2 - Day
3 - Month
Input choice: 3
Input Number: 2
February. Heart's month!

Here is my code, I only typed the Year(levels) yet because when I tried to input 2(day) and 3(month) for the Input choice and after that, Inputting a number to 1-4 would yield the same result to case 1's year levels.

#include <stdio.h>
#include <conio.h>
using namespace std;

[Code].....

how to link the case 2 to days and case 3 to months?

View 1 Replies View Related

C++ :: How To Use Getline With Switch Statement

Sep 17, 2014

I have a problem with the switch statement because it doesn't prompt me to input something.

#include <iostream>
#include <fstream>
#include<cstring>
using namespace std;
//Compiler: Dev C++ and cygwin
void rd() {
string txt;

[Code] ....

I want to get rid of this kind of output ...

View 5 Replies View Related

C++ :: Converting If / Else To Switch Statement

Oct 8, 2014

if( vehicleUse == 'C' ) // Carpool
{
// TODO: Convert to a switch statement

if( vehicleLoad == 'E' ) // 6-8
cout << "Ford Windstar" << endl;
else if( vehicleLoad == 'F' ) // 8-10

[Code] .....

View 1 Replies View Related

C++ :: Compare Value In Switch Statement?

Sep 23, 2013

is it possible to compare value in switch statement? i.e: a > b

View 5 Replies View Related

C++ :: Switch Statement As A Menu?

Nov 1, 2013

I am using a switch statement as a menu. If I enter a non-integer value as my choice, I expect the error message , "Invalid entry", to display but instead the output keeps running.

View 2 Replies View Related

C/C++ :: Switch Statement Using Seekg

Mar 21, 2014

Right now I have to use seekg to read a letter from a text document then using a switch statement i have to show what that letter is

#include <iostream>
#include <fstream>
#include <math.h>
#include <time.h>

[Code]....

View 7 Replies View Related







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