Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

hai guyz i can program

Name: Anonymous 2007-11-26 22:35

#include <cstdlib>
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
    init:
         string player_a;
         string player_b;
         int a_hp = 100;
         int b_hp = 100;
         int a_poison = 0;
         int b_poison = 0;
         int attack = 0;
         int turn = 0;
    name:
         cout << "Name PLAYER 1: ";
         cin >> player_a;
         cout << "Name PLAYER 2: ";
         cin >> player_b;
         cout << "------------------" << endl;
    disp:
         if (a_hp < 1) {
               goto b_win;  
         }
         if (b_hp < 1) {
               goto a_win;  
         }
         cout << player_a << ": " << a_hp << endl;
         cout << player_b << ": " << b_hp << endl;
         cout << "------------------" << endl;
         if (turn == 0) {
                  turn = 1;
                  goto a_turn;
         }
         if (turn == 1) {
                  turn = 0;
                  goto b_turn;        
         }
    a_turn:
           cout << player_a << "'s turn:" << endl;
           if (a_poison == 1) {
                        cout << "* * * * * * * * * * * * * *" << endl;
                        cout << "You've been hurt by poison!" << endl;
                        cout << " * * * * * * * * * * * * *" << endl;
                        a_hp -= 2;
           }
           cout << "1. Poison Strike" << endl;
           cout << "2. Fury Slash" << endl;
           cout << "Your move: ";
           cin >> attack;
           cout << "------------------" << endl;
           switch (attack) {
                  case 1: goto poison; break;
                  case 2: goto slash; break;
                  default: goto fail; break;      
           }
    b_turn:
           cout << player_b << "'s turn:" << endl;
           if (b_poison == 1) {
                        cout << "* * * * * * * * * * * * * *" << endl;
                        cout << "You've been hurt by poison!" << endl;
                        cout << " * * * * * * * * * * * * *" << endl;
                        b_hp -= 2;
           }
           cout << "1. Poison Strike" << endl;
           cout << "2. Fury Slash" << endl;
           cout << "Your selection: ";
           cin >> attack;
           cout << "------------------" << endl;
           switch (attack) {
                  case 1: goto poison; break;
                  case 2: goto slash; break;
                  default: goto fail; break;      
           }
    poison:
           if (turn == 1) {
                    b_poison = 1;       
           }
           if (turn == 0) {
                    a_poison = 1;
           }
           goto disp;
    slash:
          if (turn == 1) {
                    b_hp -= 10;       
           }
           if (turn == 0) {
                    a_hp -= 10;
           }
           goto disp;
    fail:
         cout << "lol n00b!" << endl;
         cout << "------------------" << endl;
         goto disp;
    a_win:
          cout << "*****************************" << endl;
          cout << player_a << " is victorious!!!" << endl;
          cout << "*****************************" << endl;
          system("PAUSE");
          return 0;
    b_win:
          cout << "*****************************" << endl;
          cout << player_b << " is victorious!!!" << endl;
          cout << "*****************************" << endl;
          system("PAUSE");
          return 0;
}

Name: Anonymous 2007-11-27 0:52

>>4
>>5

Explain what's so terrible about my code? I'm a noob, and I wrote it quick, so i'm sure there are better ways I could've gone about writing it.

As for reading SICP, I get bored fast with textbooks. Real fast. I think I may have ADD, actually... but anyway, the point is that I'd learn better if someone showed me the "proper" way to go about coding this.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List