C++ :: Guess Number Game - Choosing Integer At Random

Jun 11, 2013

Write a program that plays the game of guess the number.the program chooses the number to be guessed by choosing an integer at random in the range 1-1000. The program then types 'i have a number between 1 and 1000,can you guess number? Then the player then types the first guess, the program responds.

View 1 Replies


ADVERTISEMENT

C :: Guess Random Number Game

Aug 9, 2013

I have an error on my Guess the random number game.When you got the right answer it shows the "You got the right answer" and shows the "What is the number?" Here is the code.

Code:

#include<stdio.h>
main()
{
srand(time(0));
int x=rand() % 101,guess=0,tries=3;
printf("The computer will generate a random number, try and guess the random number.
}

[code]....

View 3 Replies View Related

C++ :: Guessing Game Program - Ask User To Guess Computer Generator Number

Feb 11, 2013

I'm currently creating a guessing game program where the user will be asked to guess the computer generated number. Once the program is finished, at the end the user will be asked if they want to play again. If the user types "Y or Y" the program will loop and when the user types "n or N" it will not loop. Check out my code below.

#include<iostream.h>
#include<stdio.h>
#include<dos.h>
#include<stdlib.h>
#include<conio.h>
#define g gotoxy
void main(){
int a,l,b,guess,row,col,answer,num,clue=5;

[Code] ....

I can't loop this program.

View 3 Replies View Related

C/C++ :: Choosing Random Item From Array?

Apr 27, 2015

I need to finish this program which has to ask for seed, then the user gives 5 friends, and then it will choose who to text randomly and show who did not make the cut.

This all i have, I am stuck and I do not know if it correct.

#include <iostream>
#include <string>
using namespace std;
int main() {
string num_friends[5];
int user_input;

[code]....

View 7 Replies View Related

C :: Random Number Guessing Game

Feb 13, 2013

Code:

#include <conio.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#define MAX 100
}

[code].....

I am completely stuck when assigning values to and passing variables around. It seems that the problem occurs with fscanf function. I have also guessed that it might be passing and reading it as a character, even though I said it will be an integer, and tried atoi() with no luck. I troubleshooted the error as I tried to print the given values after I assign it. I am doing this for a friend I have recently been programming django, so I am completely out of the loop when it comes to C. where I am assigning converting passing in a wrong way?

View 2 Replies View Related

C++ ::  Programming A Random Number Game

Nov 21, 2013

This is the code i have so far

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

/* function main begins program execution */
int main() {

[Code] .....

I have gotten the conditions to execute properly but will end the program after doing a case instead of asking to play again and loop. Also how would i output the number of wins and losses?

View 2 Replies View Related

C# :: Random Number Guessing Game?

Oct 13, 2014

The question for homework is Create an application that generates a random number in the range of 1 through 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” If the user guesses the number, the application should congratulate the user and then generate a new random number so the game can start over"

I have no errors in my code, but when it compiles it and I type the number in, and hit calculate nothing happens at all. Im baffled. Here is my code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code].....

View 4 Replies View Related

C++ :: Hangman Game - Generating Random Number

Sep 12, 2013

I am recreating a hangman game. I'm trying to generate a random number to choose which word from my words list to use and I've done it a billion times before just like this. So, here's my code:

#include <iostream>
#include <cstdlib> //standard library.
#include <ctime> //for random.
#include <fstream> //for reading and writing to a file.
#include <string>
using namespace std;
int main() {
int num_words;
string word[num_words];

[Code] .....

I have the text file "words.txt" info below.

5
dog
cat
horse
pig
bird

If I run the program as it is, I get a segmentation fault core dumped error, however, if I take all the stuff that reads in the words from the words.txt file, like so:

#include <iostream> //every program has this.
#include <cstdlib> //standard library.
#include <ctime> //for random.
#include <fstream> //for reading and writing to a file.
#include <string>

[Code] ....

it works correctly and generates a random number.

I'm using Linux Mint.

View 7 Replies View Related

C/C++ :: Rock Paper Scissors - Displaying Output And Choosing Random Option?

Aug 11, 2014

today I've been working on a rock, paper and scissors game. It compiles OK, except:

It doesn't use a random number from 1 -3, or goes out of scope.2. It doesn't COUT and it doesn't flush the buffer.3.

My code is as follows:

#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
std::string randomPC(int &);
void PCSelect(int &);

[code]....

View 2 Replies View Related

C :: Random Number Game - Segmentation Fault (core Dumped) Error

Jun 25, 2013

Ok, so doing an assignment for a random number game where you guess and it says too high or too low until you get it right or run out of tries. Here is what I got so far:

Code:
//Cameron Taylor

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

int main(){
srand(time(0));
int number = rand()%100+1;;
int guess, numberGuess;

[Code] ....

Getting "Segmentation fault (core dumped)" after inputting the first number, but it compiles correctly.

I later have to add "Do you want to play again (y/n)", so I will use this post to continue that later.

View 13 Replies View Related

C++ :: Math Tutor - Guess Correct Answer Of Random Numbers

Jul 11, 2014

Objective: Guess the correct answer of the random numbers

Problem: I guess the correct answer but the program keeps telling me that I'm INCORRECT.

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, const char * argv[]) {
const int MIN_VALUE = 1; // Constants
const int MAX_VALUE = 200;

[Code] ....

View 2 Replies View Related

C++ :: Choosing A Number Between Limits?

Oct 9, 2013

Im trying to choose a # between 1 and 1000 (can be 1 or 1000), error check it, but keep asking until I get the correct input.

#include<iostream>
using namespace std;
int main () {
int num;
bool goodNum;
goodNum = false;
while (!goodNum)

[code]....

This program analyzes a number, determining whether a number is prime or not, perfect or not, and output a list of all divisors for non-prime and perfect numbers.

Enter a number between 1 and 1000 then hit enter: 9000

You entered 9000.

Press any key to continue . . .

View 2 Replies View Related

C++ :: Hangman Definition Game - Extract Word Randomly Form File And User Guess The Word

Jun 25, 2014

Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.

I'm having trouble receiving that random word and I'm getting the definitions from the file.

Here's my code:

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

[Code] ....

This is what is in the words.txt file
apple#the usually round, red or yellow, edible fruit of a small tree
boat#a vessel for transport by water
horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding
television#a system for transmitting visual images and sound that are reproduced on screens
soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc.
bottle#a container, typically made of glass or plastic and with a narrow neck
barber#a person who cuts hair
toast#sliced bread browned on both sides by exposure to radiant heat
radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects
red#of a color at the end of the spectrum next to orange and opposite violet

View 3 Replies View Related

C++ :: Simulated Radio Station Holding A Contest - Guess Number / Sequential Search

Dec 14, 2014

I have an assignment to write the code for a simulated radio station holding a contest. The contest is for a "caller" (user input obviously) to guess a number from 1 to 500. The "randomly generated" numbers are already chosen and are being stored in a .txt file. The code is to search for number guessed by the caller and if they are wrong, next caller until a caller is correct. The end result is to display the winning number, the indexed location the number was found, and how many callers guessed. This is what I have...

Code:
#include<iostream>
#include<fstream>
using namespace std;
int sequenSrch(const int prizeArray[], int arrayLength, int searchedItem);
int guess();

[Code] ....

I'm not sure if I am even on the right track... when I pass something into the sequenSrh(); the code compiles, asks for the number to be guessed and ends.

View 2 Replies View Related

C++ ::  Random Integer Must Be A Constant

Mar 18, 2014

//VALID:
const int CONSTANT=100;
int integerArray[CONSTANT]={ 0 };

//but after getting input let's say:
cin>>randomInteger;
int integerArray[randomInteger]; // This is invalid.

// VISUAL STUDIO 13 Says : randomInteger must be a constant; If so?
const int CONSTANT=randomInteger; //This is also invalid.

How to get user defined

//Input in a constant variable?

How to resolve this? I know dynamically allocation other than this.

I am using VISUAL STUDIO 13 ....

View 3 Replies View Related

C :: Simulating Random Dice Roll As A Basis For Chutes And Ladders Game

Jan 24, 2014

I am trying to simulate a random dice roll as a basis for a chutes and ladders game

Code:
int main {
int i = 0, diceroll;
while (i>5) {
diceroll = 1+rand()%6;
i++;
}
return 0;
}

However the numbers get don't seem to be random, it always starts off with 6,6,5.. then its random.

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 :: Function To Round A Number To Give Integer Number That Is Closer To Real Value

Oct 9, 2013

I was told to use a round function to round a number to give an integer number that is closer to the real value. (for example if the number is 114.67 I need to print an int value of 115 instead of 114)

I am not exactly sure how a round function works, but I am told to include math.h library. What I try doesn't seem to work.

View 1 Replies View Related

C++ :: Random Number Generator Stuck On 1 Number?

Nov 21, 2013

I am working with C++ in Visual Studio. It's my first semester doing anything like this ever. Still, I am embarrassed that I am having trouble with this simple "coin flipping" program. The user tells the program how many times to "flip the coin" & then the program tells the user the results of each flip. You'll see I am randomly generating a 1 or a 2 within the function coinFlip to represent heads or tails. However, the problem is that if the user wants more than one coin flip, the "random" number stays the same for all of them, resulting in all heads or all tails. I am thinking this is an issue with the for loop that I have within the function coinFlip.

Code:

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

[Code] .....

View 3 Replies View Related

C++ :: Choosing Input Streams

May 23, 2013

So I built an interpreter for a language I made, but I can't get the streams right. I have an istream pointer and if they don't supply a cmd line arg, it references the adress of cin, which works fine. however, if they do supply a file in the form of cmd line args, i want to make it reference an ifstream. how do i do that?

View 1 Replies View Related

C :: Picking And Choosing Between User Inputs

Jul 31, 2013

I have recently looked into a self created project where I wanted to compare user input against a list of strings in an external file. That has since been completed to my great satisfaction, however it did throw up some interesting issues in my knowledge and understanding of user input..What is the best way to pick up user input i.e scanf,stdin etc. and when should either be used and can a mixture of types be used, and if so, when and why.

A quick program to take different input methods and display differnt output method (obviously corresponding i.e scanf/printf - fgets/fputs)

My first pothole came when I have setup the method for scanf - fine. Then I setup the method for fgets(test,100,stdin) for example and the fgets method no longer picks up stdin from the user..

View 3 Replies View Related

C/C++ :: Complex Number Guessing Game (SOS)

Mar 12, 2014

the only problem I have is where to add

want to play again? y
OK, I am thinking of a number. Try to guess it.
Your guess?
...

want to play again? no
Goodbye

Code :

#include <stdio.h>
#define TARGET 23
#define LOW 1
#define HIGH 100
#define TRUE 1
#define FALSE 0
#define GUESS 6
int process( int guess, int target );

[Code] ....

View 1 Replies View Related

C++ :: While Loop Age Guess

Feb 20, 2013

Write a C++ program that uses a while loop to guess a persons age, ask the user if the want to try again if no end the loop. Of course if they guess it the loop also ends

View 3 Replies View Related

C++ :: Number Guessing Game Binary Search

Sep 3, 2013

Basically i need to make a number guessing game where user thinks of a numbver from 1 - 100 and the machine will try to guess it in the least number of times. Once it guesses the number it will also say how many tries it took to guess.

My code so far is

#include<iostream>
using namespace std;
const int MAX = 100;
int main() {
char ch;

cout << "Think of an integer number between 0 and " << MAX<<endl;
cout << "Write it down on a piece of paper then hit a key to continue"<<endl<<endl;
cin.get(ch);

[Code] ....

View 2 Replies View Related

C++ :: Numbers Game - Store Current Low Number

Dec 14, 2013

I have a program that stores current a low numbers. The Object is to Store the low number every time time one is presented. so say I start the function the first number is the low number. but the trouble im having it once the function is called again it starts over(low number). Is there a way I can keep the function value once the function is called again? Any better way of doing this while keeping function in a class?

double a;
class rff{
public:
void FGH() {
doubleb=0;
cout<< "pick a number"<<endl;

[Code] ....

View 1 Replies View Related

C++ ::  Random Number Between 7 To 10

Nov 27, 2013

I'm trying to generate random number from 7 to 10 but all i got is "Error C2661: 'rand' : no overloaded function takes 1 argument"

there is my code:

#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void init_Function(); // init function

[Code] .....

View 4 Replies View Related







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