Small program problem.

I am fairly new in C++ and I have started a new program, I however am having problems with the functions, can someone tell me what's wrong?

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

int main()
{

int jailt;
int bank;
int firstmurder;
int gta;
int Hacking;
int crime;
int exit;

    cout << "Welcome to Jailtime, it is a small mini-commandline game.\n";
    cout << "You have 2,000 dollars in your bank account.\n";
    cout << "Please enter your crime\n";
    cout << "First Degree Murder, Grand Theft Auto (gta), Hacking.\n";
    cout << "Crime: ";
    cin >> crime;
    if ( crime == Hacking ) {
  // Executes as that the user is going to jail as a hacker.
  Hacking = 2;
  Hacking + 0;
  "You will go to jail for 2 years.";

}
    else if ( crime == gta ) {
         //Executes that the user is going to jail for gta.
         gta = 5;
         bank = 2000 - 6000;
         bank - 6000;
         cout << "You have gone to jail for 5 years and will be in 4,000 dollars in debt.\n";
         
}
  else if ( crime == firstmurder ) {
  // Execute that the user is going to jail for murder.
  firstmurder = 300;
  firstmurder + 0;
  cout << "You go to jail for 4 life sentences.";

}
  cout << "To exit, please type exit.";
  cin >> exit;
  return 0;
}
Last edited on
Quite a few things are wrong with this unfortunately...

First, it'd be better if you posted with
[code][/code]
tags instead of quote/output.

Now for the code:
Bug: You ask users for a numerical value indicating a crime but don't mention what these values are.
Error: You're using an unknown value (stored in your variables) in a comparison.
Bug: "Hacking = 2" is pointless after you've already tried to use it whilst undefined, and then after this it is not used in futer
Bug: "Hacking + 2" this statement LITERALLY does nothing

Repeat all the above errors and bugs for each of the following variables as they're all present:
Hacking, gta, firstmurder, bank

Bug: The program is not looped and also doesn't check the value of exit at the end anyway so there is no need to type "exit", any non-whitespace character will be taken and the program will exit

NOTE The things marked "bug" will most likely compile anyway, you may get warnings in the log/output but it shouldn't stop the .exe being made, however they do not do as intended (or in some cases here they don't do anything at all)
The things marked in "error" I expect will make the compiler complain and quit the building process... however I have seen cases where some "silly" compilers let uninitialised variables through and it's just set to whatever junk was last in it's current memory location.
Last edited on
Topic archived. No new replies allowed.