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


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++ :: 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 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# :: 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/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++ :: 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++ :: Number Guessing Game - Play Again Loop Broken

Sep 11, 2013

OK, so the program is working minus the play again loop. I even tried a goto statement for it but no luck. Basically what its doing is after the game runs its course it asks if you would like to play again? If you hit Y it starts over but if you it N it starts over. I want it to out put thank you for playing and close after user hits a button.

// C// Guess My Number
// The classic number guessing game

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

[Code] ....

View 1 Replies View Related

C++ :: Program To Play Numbers Guessing Game

Dec 14, 2014

"Write a program to play a numbers guessing game. The user thinks of a number between 1 and 100 and your program asks questions to figure out what the number is (e.g., "Is the number you are thinking of less than 50?"). Your program should be able to identify the number after asking no more than seven questions. Hint: Use < and <= opeartors and the if-else construct."

What I've managed so far, but what I have seems to be lacking

Code:
#include "../../std_lib_facilities.h"

int half(int guess);
int going_up(int i);

int main()

[Code] ....

View 4 Replies View Related

C :: Arithmetic And Guessing Game Program Not Working Right

Nov 8, 2013

I am relatively new to C programming, and I am encountering numerous issues with this program that I cant seem to figure out how to fix.

First, when the user selects the arithmetic game, I keep on getting different incorrect answers from the arithgame function. For example, when I am presented with the question 3+2=_, sometimes the function claims the answer is the first number, 3, and other times the function gives me a multiplication answer, 6. This happens in both the addition and multiplication parts (ie. the multiplication answer will either be the first number or the addition answer).

Additionally, I cant figure out why my guessing game loops forever, rather than letting me guess until I get a correct answer.

View 2 Replies View Related

C :: Arithmetic / Guessing Game - Program Won't Compile?

Nov 8, 2013

Need getting my program to compile.

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

//prototypes
int arithGame(int max, int op);
int guessGame();

[Code] .....

View 3 Replies View Related

C :: Guessing Game Program - Binary Search

Apr 5, 2014

I'm playing with a guessing game program as a personal exercise, but I'm missing a vital piece - the binary search-style code.

"Have the program initially guess 50, and have it ask the user whether the guess is high, low, or correct. If, say, the guess is low, have the next guess be halfway between 50 and 100, that is, 75. If that guess is high, let the next guess be halfway between 75 and 50, and so on."

(We're assuming that the user won't cheat.) I need the average, essentially. As in, (50 + 75) / 2 = 63.. but when I use this method of "guess = (high+low)/2, it just keeps giving me 50. I can't remember what operators I should use to increment the program's response based on the user's input. It's literally a binary search, that needs to go where those TODOs are. If low was chosen, it would have to start by being at least 51, to 100, so I'd have to set that, then find the average.

Code:
#include <stdio.h> Code: #include <ctype.h>
int main(int argc, const char * argv[]) {
int low;
int high;
int guess;
int response;
int toupper ( int );

[Code] ....

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++ :: Random Number Generator - How To Get User Inputs

Sep 10, 2013

I want to program a program that produces a random number between 1-10, then if the number is correct, says like HEY GOOD JOB and if its not says try AGAIN! also, at any point the user can quit by typing in X.

I know that I can use stuff like cout << "Hey put in a guess now" to prompt the user but I dont know how to accept inputs.

For example, how do I use scanf to do this?

I know that if I use scanf, it takes in a value, but where the heck does it store it?

eg. scanf(%s,guess);

Is that valid? I get an invalid expression error when trying to use that in C++.

View 3 Replies View Related

C++ :: User Input Number And Then Computer Calculates It For Fibonacci Series

Mar 15, 2013

I was asked to write a code that has the user input a number and then the computer calculates it for the Fibonacci series. The output should be separated by commas and a period should follow the last number. Ex. 1,2,3,4,5. <---period

I can't seem to get the period at the end. I have the commas and everything else. Here is my code:

#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double num;

cout << "How many Fibonacci numbers do you want to display?";

[Code] ....

View 3 Replies View Related

C++ :: Program To Check If User Presses Power Button On Computer

Jun 19, 2014

How you can make a c++ program that checks to see if the user presses the power button on their computer? And if so, how?

View 1 Replies View Related

C++ :: Creating A Random Number Generator Program?

Aug 9, 2012

I'm trying to create a program that creates random numbers. I looked through some examples and this is what I came up with. The time identifier seems to be undefined yet I see no reason it is undefined.

Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
//Re-seed the random-number generator
time_t now;

[code]...

here's my error code..

1>------ Build started: Project: bake, Configuration: Debug Win32 ------
1> bake.cpp
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(8): error C3861: 'time': identifier not found
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

View 2 Replies View Related

C++ :: Guessing Game With Numbers Between 1 And 100

Apr 22, 2014

I neeed to Create a guessing game with numbers between 1 and 100. The loop will never exit until the condition is met. The user will continually guess and display:

Sorry Too Low
Sorry Too High
You Guessed Right

** YOU MUST USE THE BOOLEAN VARIABLE… when the boolean is true, the loop will exit **

This is what i got so far;

#include <iostream>
using namespace std;
int main() {
//Declaring Variables
int guess=50,x;

[Code] .....

View 2 Replies View Related

C :: Make A Simple Letter Guessing Game?

Oct 2, 2013

when it comes to programming. I was trying to make a simple letter guessing game where the user has 6 chances to guess the letter V. The command prompt works fine until the user enters 'y' to play. It repeats my HIGH & LOW statements twice before letting me guess again. It's all a mess.

View 2 Replies View Related

C++ :: Guessing Game - Stack Around Variable Was Corrupted

Jan 12, 2013

I'm making a guessing game program and i've encountered this error of stack around variable ' ' was corrupted. I tried to replace the variable into others but still the same. So is there anyway to solve it?I only know how to use stdio.h so preferably solution using it. Here is my program:

#include <stdio.h>
#include <iostream>
void main() {
char choice;
int num[4][4]={2,1,3,4,5,6,7,8,9,10,11,12,13,14,15,2};
int i,k,row,col,x,y;
int Array[4][4];

[Code] ....

The words in bold is the error part of the program...

View 1 Replies View Related

C :: Letter Guessing Game - Looping Till Exit

Oct 23, 2013

So I made a simple letter guessing game a while ago and I want to make a simple edit. If the user does not press 'y' or 'n' and instead inputs an invalid letter, I want the printf's in the main function to loop until the user chooses to play or quit.

And I want the choices to show up again at the end of a game. Basically I want it to keep asking if the user wants to play until the user chooses to exit. Here's my code:

#include <stdio.h>
#include <time.h>
#define MAX_GUESSES 6
void Instructions ( ); //displays instructions, returns nothing
char Play ( ); //this functions plays one game, returns W if user wins & L if user runs out of tries

[Code] .....

I'm thinking of making a separate function (like Instructions and Play) ... But how would I link the user input back to the main function?

View 3 Replies View Related

C++ :: Guessing Game - How To Successfully Loop Back To The Beginning

Feb 5, 2015

So I'm making my first program w/ C++ and its a game guessing game. I've learned how to use booleans, chars, strings, if/else, loops, and input. Anything past that I dont know. I've gotten my game to work properly except for the fact that when you guess incorrectly, the program closes. I want the program to go to the beginning of the program again so the user can restart. So far i've gotten the loop to beginning thing to work but not well. It'll only repeat twice before closing again and it'll say the user got the wrong answer even if it was correct. Here's my code

#include <iostream>
#include <string>
#include <random>
#include<ctime>
using namespace std;

int game(){
string playerName;
int guess;

[Code] ....

View 1 Replies View Related

C++ :: Creating Computer AI For Tic Tac Toe Game

Dec 24, 2014

How I can go about creating a computer AI given the way that I structured my code.

main.cpp

Code:
#include <iostream>
#include "Board.h"
#include <limits>
#include <cctype>
using namespace std;
int main() {
// Welcoming message.

[Code] ...

View 14 Replies View Related

C/C++ :: Keeping List Of User Guesses And Output Message If Guess Is Duplicate

Apr 19, 2015

The label "You already picked that" doesn't always appear. Sometimes it does, but only if a duplicate has been entered at least 3 times. I haven't been able to correct this. I am new to programming and array-based lists.

//Objective: randomly generate an integer between 1 and 100, input user guess as to what number it is, and output "correct!" if user guess is the random number, or output "Too high" if the user guess is too high, or output "too low" if the user guess is too low, "you already entered __" if a duplicate is entered and allow the user to keep guessing until they guess the correct number

//libraries
#include <ctime>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
struct Guess {

[Code] ....

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







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