Ravioli
Microboner
- Joined
- Nov 1, 2004
- Messages
- 5,097
- Reaction score
- 2
Decided to learn a bit of C++ coding by myself just for the heck of it. Right now im trying to create a very simple "game" if you can call it that. Basically it asks you how much money you have, and you put the number in. Then you get to choose one of 3 houses, all with different prices. Then it subtracts the price of the house with whatever money you said you had, and then tell you how much money you have left.
The program executes, however, it doesnt do the calculations for the remaining money. Instead, at the end it just states whatever money you first said you had, instead of subtracting it by the price of the house. So i must have coded the actual calculation wrong, heres the code:
I even tried replacing money + house1; with money - 3000; but it still didnt work.
Also, on a side note. Whenever i run the program as a finished compiled .exe, it exits the DOS prompt as soon as the program is finished, how do i make it remain on screen?
The program executes, however, it doesnt do the calculations for the remaining money. Instead, at the end it just states whatever money you first said you had, instead of subtracting it by the price of the house. So i must have coded the actual calculation wrong, heres the code:
// house game.cpp : main project file.
#include "stdafx.h"
#include <iostream>
using namespace std;
using namespace System;
int main()
{
int money;
int house1;
int house2;
int house3;
char choice;
house1 = -3000; //Price of the house
house2 = -5000;
house3 = -2000;
cout << "How much money do you have?\n";
cin >> money; //The money you have
cout << "What house would you like to buy?\n";
cout << "House1 for 3000\n";
cout << "House2 for 5000\n";
cout << "House3 for 2000\n";
cin >> choice;
switch(choice) { // case 1 represents House1 etc
case '1':
money + house1; // subtracts 3000 from money, the actual calculation, but it doesnt seem to do it.
cout << "You have " << money << " left\n";
break;
case '2':
money + house2;
cout << "You have " << money << " left\n";
break;
case '3':
money + house3;
cout << "You have " << money << " left\n";
break;
default:
cout << "Invalid Choice"; // if a choice other than 1,2,3 is made
}
return 0;
}
I even tried replacing money + house1; with money - 3000; but it still didnt work.
Also, on a side note. Whenever i run the program as a finished compiled .exe, it exits the DOS prompt as soon as the program is finished, how do i make it remain on screen?