Thread: C++ Help
View Single Post
Old 07-02-2009, 10:23 AM   #27 (permalink)
Oreo
 
*^[#@"'.,;:\|/:;,.'"@#]^*

Join Date: Dec 2006

Location: Leicester, England

Posts: 3,659

Oreo will become famous soon enoughOreo will become famous soon enough

Send a message via MSN to Oreo
Default Re: C++ Help

I'll post the key bits of our game code:

Code:
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <cmath>
Code:
srand(time(NULL));

	char answer[4];
	int stat, strength, defence, choice2, pot1, pot2, pot3, pot4, outcome, test;
	char choice;
Code:
	cout << "\nStrength: ";
	cin >> strength;

	cout << "\nDefence: ";
	cin >> defence;
Code:
		cout << "You reach a road, do you want to turn left or right ?\n\n";
		cout << "1, Left: Danger, 30percent. Stat Potential Increase, 30ppercent\n\n";
		cout << "2, Right: Danger, 60percent. Stat Potential, 70percent \n\n";
		cout << "Enter choice (1 or 2): ";
		cin >> choice2;
		cout << "\n";
	
		switch(choice2) {

Code:
	case 1: 
            
		
		pot1 = 5;

		if(pot1 == 4)
		{

			cout << "You encounter no dangers, your stats remain the same\n\n";
		}
		else
		{

		cout << "-------Start of Battle------";
		cout << "\n\n\n";

			cout << "You encountered a Black Bear (Level 15)\n";

			cout << "\nStrength is: " << strength << "...Defence is: " << defence;
			stat = strength + defence;
			cout << "\n\n";
			
			cout << "Stats equal: " << stat;

Thats about halfway through the code, skipping bits which arn't particularly important.
In the last bit of code, pot1 is purposely set as 5 so the 2nd else executes not the first, it will actually be defined by a random number when i have this problem sorted. When i execute the code, you see where cout << stat; is ? well that stat should equal strength + defence. Instead it comes out with some random number from nowhere.
Oreo is offline