Hi. I'm making a text adventure game and I was wondering how I could randomize a number. (BELOW IS A PART OF MY CODE)
Score is declared earlier in the code. I want right_Way to randomize a number between 1 or 2
// The Which way to go loop
while (game_Is_Running == 1) {
// generate the right way
right_Way = 2; // I want right_Way to equal 1 or 2
cout << "You come across a two-way intersection. You can go left (1) or right (2)" << endl;
cout << "Which way do you want to go?" << endl;
cin >> user_Input;
if (user_Input == right_Way) {
cout << "Congrates! You picked the right way!" << endl;
score = score + 1;
cout << "Your score is now " << score << endl;
system("pause");
system("cls");
}else {
cout << "You picked the wrong way..." << endl;
score = score - 1;
cout << "Your score is now " << score << endl;
system("pause");
system("cls");
}
}
2 errors, 1 warning. Error1: missing type specifier - int assumed. Note: C++ does not support default-int. Error2: 'srand' : redefinition; previous definition was 'function' Warning: 'initializing' : conversion from 'time.t' to 'int', possible lose of data
#include "stdafx.h"
#include <iostream>
#include <string>
#include <time.h>
#include "windows.h"
usingnamespace std;
srand(time(0));
int game_Is_Running = 1;
int main ()
{
// Intro
cout << "Welcome to The Cave of Two Lovers." << endl;
cout << "By OR Software." << endl;
cout << "http://www.ORSoftware.netne.net/" << endl;
system("pause");
system("cls");
int user_Input, right_Way, score;
string character_Select,character_To_Go_With;
// Game
loop:
cout << "You come across a cave with team avatar...." << endl;
system("pause");
cout << "Who do you want to be? (Aang, Sokka, or Katara)" << endl;
cin >> character_Select;
// Check what character they want to be
if (character_Select == "Aang") {
// Play as aang
cout << "You have chosen to be Aang." << endl;
system("pause");
system("cls");
cout << "You enter the cave..." << endl;
system("pause");
cout << "You walk in with Sokka, and Katara." << endl;
system("pause");
system("cls");
cout << "The wall is starting to collapse. You have a choice to go with Katara or Sokka." << endl;
system("pause");
cout << "Who do you go with? HURRY YOU HAVE TO PICK SOON!" << endl;
cin >> character_To_Go_With;
if (character_To_Go_With == "Katara") {
// Go with Katara
int love; // How much love you and Katara have.
system("cls");
cout << "You and Katara are now alone...." << endl;
system("pause");
cout << "You can't stop thinking about your love for her," << endl;
cout << "So that will delay you're thinking and reaction time." << endl;
system("pause");
system("cls");
cout << "It's really dark. Katara asked you to hold her hand." << endl;
cout << "But you also have torches." << endl;
system("pause");
cout << "What do you want to do?" << endl;
int hold_Katara_Hand;
cout << "(1 = Hold her hand ; 2 = Light a torch)" << endl;
cin >> hold_Katara_Hand;
system("cls");
if (hold_Katara_Hand == 1) {
// Continue through the cave holding her hand. (LOVE INCREASES BY 1)
love = love + 1;
cout << "You and Katara now have a love of " << love << endl;
system("pause");
system("cls");
// The Which way to go loop
while (game_Is_Running == 1) {
// generate the right way
right_Way = rand() % 2 + 1;
cout << "You come across a two-way intersection. You can go left (1) or right (2)" << endl;
cout << "Which way do you want to go?" << endl;
cin >> user_Input;
if (user_Input == right_Way) {
cout << "Congrates! You picked the right way!" << endl;
score = score + 1;
cout << "Your score is now " << score << endl;
system("pause");
system("cls");
}else {
cout << "You picked the wrong way..." << endl;
score = score - 1;
cout << "Your score is now " << score << endl;
system("pause");
system("cls");
}
}
}