Calling upon a random number in IF statement

We have generated a random number (0 - 9999) and we have made it a constant variable. Now, our question is: How do we call it for an input?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// computerpasswordcw.cpp
// #include <disclaimer.h>

#include "computerpasswordcw.h"
#include <windows.h>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <limits>
#include <conio.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\clearscreen.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\computerusername.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\computerlogincw.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\office1a.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\numsave.h>
using namespace std;
void computerpasswordcw()
{
     
     char computerpasswordcw[80];
     char FAIL[] = "The password is not registered. Please try again.";
     char donow[] = "\nYou can type 'leave' at any time to exit.\n\nPlease enter your password: ";
     char help[] = "Examine (object), move (left, right, forward, back) \npick up, use (object), attack/kick (object), enter (room)";
     cout << "Please enter your password: ";
     cin.getline(computerpasswordcw, 80);
    bool done = false;
    while (!done){
     if ((computerpasswordcw, numsave) == 0){ //This is our problem.
                        ClearScreen();
                        computerlogincw();
                        }
     if (strcmp(computerpasswordcw, "leave") == 0){
                        ClearScreen();
                        office1a();
                        }
     cin.getline(computerpasswordcw, 80);
     ClearScreen();
     cout << FAIL;
     cout << donow;
}
}


"numsave" is our frozen number and we need to input it as a password to login.
closed account (S6k9GNh0)
1
2
3
4
5
#include <C:\Documents and Settings\strasbourgau\Desktop\clearscreen.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\computerusername.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\computerlogincw.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\office1a.h>
#include <C:\Documents and Settings\strasbourgau\Desktop\numsave.h> 
Dear god...

// #include <disclaimer.h>
I definitely laughed out loud on this one.

In all seriousness, this expression, (computerpasswordcw, numsave) doesn't do anything (well, it does, just nothing useful.. although I'm surprised this compiles without warning).

And the rest of the code looks incredibly sketchy. I'm having issues taking this seriously. Please elaborate on your question.
Last edited on
In reply to computerquip:

We are making a text based game, not unlike zork. We have coded a basic computer that reveals databases non-essential to our plot, but nonetheless important.

We have it so the number is generated once you launch the game, and is stored and frozen as that one number that will not change throughout the game. We have confirmed both of these assumptions.

Our question is that, once the number is generated, we would like to use it for a password, but since it is a randomly generated number it will be a different # every time you launch the game. The random number, represented by 'numsave', is to be the password that you see up top.

1
2
3
4
if ((computerpasswordcw, numsave) == 0){ //This is our problem.
                        ClearScreen();
                        computerlogincw();
                        }


We need to get this to mean: If you type the random number, or 'numsave', then it will transfer you into computerlogincw.

I hope this clears up any confusion you may have.
closed account (S6k9GNh0)
For starters, I wouldn't name a variable the same as a function. It's rather confusing.

Moving on, you need to either convert the number into a string, or the string into a number. You can do this via either stringstreams or the C std library (http://cplusplus.com/reference/clibrary/cstdlib/).

Store the converted number and then compare like so where "tmpUserPW" is the converted string into an integer:
1
2
3
4
if (tmpUserPW == numSave) { 
ClearScreen(); 
computerlogincw();
}

I'd suggest a better naming scheme.
Last edited on
Topic archived. No new replies allowed.