Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

I am stuck....

Think you can spy out that little nasty bug? Try debugging some code in here

I am stuck....

Postby jeezcak3 on Sat Jul 18, 2009 2:48 am

Please take a look.... I just finished learning "passing variable" and recommened by antiRTFM to write a "simple" program?
At this point I am not supposed to get class involved. In this case, I want the player to continuously fight with enemies of different races until his health is 0. Though, after a fight, player would get to heal. just like attack power and defense, user will have to input a number and that number will be calculated for an output that will be subtracted/added to health. Please take a look and correct me as much as you can. I am far away from completion so there might be minor errors that I haven't fixed. Thanks!

Code: Select all
#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;

void raceHuman(int a, int b, int c);
void raceOrge(int a, int b, int c);
void raceUndead(int a, int b, int c);

void raceSelect()
{
       int raceSelect;
       cout << "Please select your desired race" << endl;
       cout << "1. Human" << endl;
       cout << "2. Orge" << endl;
       cout << "3. Undead" << endl;
       cin >> raceSelect;
      
      int x;
   
       switch (raceSelect)
       {
       case 1:
       {
               int health = 20;
               int strength = 6;
               int armor = 4;

               cout << "You have selected Human.\n";

               for(x, health <= 0,health - defense());
            {
            
            }

            
               y =

               break;
       }
       case 2:
       {
               int health = 25;
               int strength = 8;
               int armor = 1;

               cout << "You have selected Orge.\n";

               raceOrge(health, strength, armor);
               cout << health << strength << armor;
               break;
       }
       case 3:
       {
               int health = 30;
               int strength = 9;
               int armor = 0;

               cout << "You have selected Undead.\n";

               raceUndead(health, strength, armor);
               cout << health << strength << armor;
               break;
       }
       default:
       cout << "please hit either 1, 2, or 3 key . Then press enter to select your race. \n";
       break;
       }

}

int main()
{
       string charNAME;
       cout << "Please enter your character's name: ";
       getline(cin,charNAME);

       cout << "welcome, " << charNAME << ". Please select a map: \n";

       int mapSelect;
       cout << "Select a map you would like to conquer:" << endl;
       cout << "1. Lalaland" << endl;
       cout << "2. Go'thah" << endl;
       cout << "3. Bloodthurst" << endl;
       cin >> mapSelect;

       switch (mapSelect)
       {
       case 1:
               raceSelect();

               break;
       case 2:
               raceSelect();
               break;
       case 3:
               raceSelect();
               break;
       default:
       cout << "please hit either 1, 2, or 3 key. Then press enter to select a map. \n";
       }
       char f;
       cin >> f;
return 0;
}

void raceHuman(int health, int strength, int armor)
{
               int heal;
}

void raceOrge(int health, int strength, int armor)
{
               int heal;
}

void raceUndead(int health, int strength, int armor)
{
               int heal;
}

int defense()
{
   int z;
   cout << "Enter a number to defend yourself: ";
   cin >> z;
   health -= raceOrge(strength) - (armor % z);   
/*

   if (health <= 0)
   {
   cout << "You are killed by your enemies!" << endl;
   goto gameMenu()
   }
   else
   {
   cout << "Congratulations! You have killed your enemy. \n";
   cout << "Next one is coming...." << endl;
   }
   continue; */
   return x;
}
jeezcak3
 
Posts: 8
Joined: Thu Jul 16, 2009 3:06 pm

Re: I am stuck....

Postby Meltra Bour on Sat Jul 18, 2009 5:31 am

Change 01 :: 'for(x, health <= 0, health - defense());' Inside for() you are supposed to use ';' and not ','
Change 02 :: 'y =', that's half a statement there, no ';' behind it and no value to put in 'y' ether ?
Change 03 :: in the int defense() function you did not initialize the variables. health, strength, armor and x do not exist in that scoop where did they come from ?

Those are just the errors my IDE threw at me after copy/pasting the code ... making the rest of it work would be like doing the work for you and I'm lazy.
Did you even try to compile it ? if so your compiler should have pointed you to allot off silly errors ... What ide/compiler are u using ?
Meltra Bour
 
Posts: 8
Joined: Tue Jul 14, 2009 6:46 am


Return to Debug

Who is online

Users browsing this forum: No registered users and 0 guests

cron