Help with FINAL assignment

This is a discussion on Help with FINAL assignment within the C++ Programming forums, part of the General Programming Boards category; i am a TOTAL n00b at C++, i dont think i know how to use for loops rite. this is ...

  1. #1
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14

    Help with FINAL assignment

    i am a TOTAL n00b at C++, i dont think i know how to use for loops rite.

    this is all i have so far:
    Code:
    #include <iostream.h>
    #include <ctype.h>
    #include <time.h>
    
    int main()
    {
    int health, counter=0, choice, scorpian, terminator, katana, movenum;
    
    {
    cout<<"Welcome to Fight Arena!"<<endl<<endl;
    cout<<"Please choose a fighter you wish to use"<<endl<<endl<<endl;
    
    cout<<"Scorpian (Press 1 to choose)"<<endl;
    
    cout<<"Strength        ***"<<endl;
    cout<<"Speed           ***"<<endl;
    cout<<"Special move    *****"<<endl<<endl<<endl;
    
    cout<<"Terminator (Press 2 to choose)"<<endl;
    
    cout<<"Strength        *****"<<endl;
    cout<<"Speed           **"<<endl;
    cout<<"Special move    ****"<<endl<<endl<<endl;
    
    cout<<"Katana (Press 3 to choose)"<<endl;
    
    cout<<"Strength        ***"<<endl;
    cout<<"Speed           *****"<<endl;
    cout<<"Special move    ***"<<endl<<endl<<endl;
    }
    
    cin>>choice;
    
    if (choice==1)
    {
    cout<<"You chose Scorpian!"<<endl;
    }
    
    if (choice==2)
    {
    cout<<"You chose Terminator!"<<endl;
    }
    
    if (choice==3)
    {
    cout<<"You chose Katana!"<<endl;
    }
    
    cout<<"1 is kick, 2 is punch, 3 is special move (when meter is full)"<<endl;
    
    cout<<"Opponent 1, Scarface"<<endl<<endl;
    cout<<"Begin!"<<endl;
    
    for(int x=0; x<4; x++);
    {
    cout<<"Kick(1), or punch(2) ?"<<endl;
    cin>>movenum;
    
    
    
    
    
    
    
    
    
    
    
    return 0;
    }
    i need to somehow incorporate:

    For loops
    Arrays
    Structs
    functions

    please help...thx in advance

    p.s. this is a fighting game if you havent figured it out


    Code tags added by Hammer.

  2. #2
    Registered User
    Join Date
    Jun 2002
    Posts
    230
    You were missing a closing bracket at the end of your for loop. Just count them. I commented it so you can see.

    Code:
    #include <iostream.h>
    #include <ctype.h>
    #include <time.h>
    
    int main()
    {
    int health, counter=0, choice, scorpian, terminator, katana, movenum;
    
    {
    cout<<"Welcome to Fight Arena!"<<endl<<endl;
    cout<<"Please choose a fighter you wish to use"<<endl<<endl<<endl;
    
    cout<<"Scorpian (Press 1 to choose)"<<endl;
    
    cout<<"Strength ***"<<endl;
    cout<<"Speed ***"<<endl;
    cout<<"Special move *****"<<endl<<endl<<endl;
    
    cout<<"Terminator (Press 2 to choose)"<<endl;
    
    cout<<"Strength *****"<<endl;
    cout<<"Speed **"<<endl;
    cout<<"Special move ****"<<endl<<endl<<endl;
    
    cout<<"Katana (Press 3 to choose)"<<endl;
    
    cout<<"Strength ***"<<endl;
    cout<<"Speed *****"<<endl;
    cout<<"Special move ***"<<endl<<endl<<endl;
    }
    
    cin>>choice;
    
    if (choice==1)
    {
    cout<<"You chose Scorpian!"<<endl;
    }
    
    if (choice==2)
    {
    cout<<"You chose Terminator!"<<endl;
    }
    
    if (choice==3)
    {
    cout<<"You chose Katana!"<<endl;
    }
    
    cout<<"1 is kick, 2 is punch, 3 is special move (when meter is full)"<<endl;
    
    cout<<"Opponent 1, Scarface"<<endl<<endl;
    cout<<"Begin!"<<endl;
    
    for(int x=0; x<4; x++);
    {
    cout<<"Kick(1), or punch(2) ?"<<endl;
    cin>>movenum;
    } // I ADDED THIS ONE
    return 0;
    }
    Also your for loops is messed up. It only asks you once to fight. Maybe you should use a while loop instead. If you need help ask for help on the loop to cuz im not sure what you need help on.
    Last edited by gamer4life687; 12-30-2002 at 07:10 PM.
    C++ Rules!!!!
    ------------
    Microsoft Visual Studio .NET Enterprise

  3. #3
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14
    sorry my Question was unclear, but hw can i incorporate

    For loops
    Arrays
    Structs
    functions
    ?
    i just started on this and have no idea how to incorporate them

    thx in advance, all ideas welcome.

  4. #4
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Originally posted by ray
    sorry my Question was unclear, but hw can i incorporate

    For loops
    Arrays
    Structs
    functions
    ?
    i just started on this and have no idea how to incorporate them

    thx in advance, all ideas welcome.
    Personally, I'd create a class called fighter that would contain member functions like punch() and kick(), but I'm guessing that you're not quite there yet; so, you can make the fighters structs that would contain their health, special meter, etc. Your functions would then be fight() and punch(), and you could have a function battle() that would have as an argument the enemy. As for arrays, hmmm, that one's a bit tougher to incorporate . . . . Oooh! I got it!
    Code:
    figther opponents[num_of_opponents];	// declare an array full of all of your opponents
    for(int i = 0; i < num_of_opponents; ++i)
    	battle(opponent[i]);
    Wow, I'm pretty happy that I came up with that. Now, I kind of wish I could code out the rest. Oh well, I hope that helped. Oh, one more thing—what gamer4life said was correct, you shouldn't use a for loop the way you did. The battle should go on while(player.health > 0) or something like that.

    I hoped that helps you with your assignment and puts you well on your way. If you have any more questions or need help implementing that, just let us know. Have fun!
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  5. #5
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14
    wow, is there another program i can do that is simpler than this that incorporates all of the above?

  6. #6
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    I suggest you make a Fighter struct containing all the attributes, and then initializing all your fighters like so:

    Code:
    struct FIGHTER
    {
         int strength;
         int speed;
         int special;
    };
    
    int main() { FIGHTER Scorpion, Terminator, Katana; }
    You have obnoxiously redundant braces around your output...Perhaps you would want to create a menu() function if a statement block is what you fancy.

    What a lot of newbies complain about is that when a user inputs something other than an int, their program crashes. So, provide something more dynamic like so:

    Code:
    char choice[100];
    
    /* Display choices*/
    
    gets(choice);
    
    switch(choice[0])
    {
    case '1':
         // .... break;
    case '2':
         // .... break;
    case '3':
         // .... break;
    default:
         cout << "ENTER AN INT YOU FOOL\n";
         break;
    }
    Last edited by abrege; 01-02-2003 at 03:56 PM.
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  7. #7
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    This program can be done very simply...
    You create a class player, like joshdick said, and give it some attributes( variables ) like stength, speed whatever, and health, and have some functions like kick or punch, etc... each of them decreases the health, untill you reach a state where health is 0, so the player is killed or defeated...
    You creat two objects of that class, and make them fight, now try writting the class, and post what you have and I will be happy to help you with it...
    In fact it's very easy, and I hope you enjoy it...

    ::Waiting your code::
    none...

  8. #8
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14
    ok what i have now is this:



    #include <iostream.h>
    #include <ctype.h>
    #include <time.h>


    struct FIGHTER
    {
    int strength;
    int speed;
    int special;

    int main() { int FIGHTER Scorpion, Terminator, Katana; }

    {
    int health, counter=0, choice, scorpian, terminator, katana, x, choice1, a, b;
    {
    cout<<"Welcome to Fight Arena!"<<endl<<endl;
    cout<<"Please choose a fighter you wish to use"<<endl<<endl<<endl;

    cout<<"Scorpian (Press 1 to choose)"<<endl;

    cout<<"Strength ***"<<endl;
    cout<<"Speed ***"<<endl;
    cout<<"Special move *****"<<endl<<endl<<endl;

    cout<<"Terminator (Press 2 to choose)"<<endl;

    cout<<"Strength *****"<<endl;
    cout<<"Speed **"<<endl;
    cout<<"Special move ****"<<endl<<endl<<endl;

    cout<<"Katana (Press 3 to choose)"<<endl;

    cout<<"Strength ***"<<endl;
    cout<<"Speed *****"<<endl;
    cout<<"Special move ***"<<endl<<endl<<endl;
    }

    cin>>choice1;

    if (choice1==1)
    {
    cout<<"You chose Scorpian!"<<endl;
    }

    if (choice1==2)
    {
    cout<<"You chose Terminator!"<<endl;
    }

    if (choice1==3)
    {
    cout<<"You chose Katana!"<<endl;
    }

    cout<<"1 is kick, 2 is punch, 3 is special move (when meter is full)"<<endl;

    cout<<"Opponent 1, Scarface"<<endl<<endl;
    cout<<"Begin!"<<endl;
    cin>>choice;


    for (x=0; x<4; x++)
    {
    if (choice==1) ?
    {


    switch (a)
    {
    case 0: cout<<"You have kicked ";
    break;
    }

    switch (b)
    {
    case 0: cout<<"and scored a direct hit"<<endl;
    break;

    case 1: cout<<"and have been blocked"<<endl;
    break;

    case 2: cout<<"and have been countered and the force of the blow has injured you"<<endl;

    }
    }


    }

    if (choice==2)
    {
    cout<<"You have punched "<<endl;
    }

    for (x=0; x<11; x++) // this i plain just dont get...
    {
    if ((choice==3)||(x>=5))
    {
    cout<<"You have unleashed your special move on your opponent "<<endl;
    }

    if ((choice==3)||(x<=4))
    {
    cout<<"You do not have enough energy to use your special move"<<endl;
    }
    }














    return 0;
    }

    i dont get the struct at the begginingat all. for my cases, how do i randomly pair switch(a) case to the switch (b) ones? and how can i do that special move for loop?

    thx in advance for help.

    on a side note, i use dev C++ 4.9.6.0 and everytime i try and compile programs that have worked in school, it says "#include expects 'FILENAME' or <FILENAME>" so i cant compile anything at home... suggestions?

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    87
    Yep, what I think happens is; In MSVC++ which most schools use, the system is really annoying, they say you have to make a project, whereas in DEV-C++ (which I use) you just use the simple source code and compile it. I have found that some files in MSVC++ aren't in DEV-C++ under the same filename. Though most are, so check you have defined your include directory in options correctly.
    **********************
    *==================*
    * Many Can. One Must... *
    *==================*
    **********************

  10. #10
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    Does this code compile.. I think you have many errors, for example, the definition of the structure FIGHTER, and many more... Just check it out one more time, and try fixing some errors, and post the results here, and I'll help you out...
    none...

  11. #11
    ray
    ray is offline
    Registered User
    Join Date
    Nov 2002
    Posts
    14
    #include <iostream.h>
    #include <ctype.h>
    #include <time.h>


    int main()
    {
    int health, counter=0, choice, scorpian, terminator, katana, x, choice1, a, b;
    {
    cout<<"Welcome to Fight Arena!"<<endl<<endl;
    cout<<"Please choose a fighter you wish to use"<<endl<<endl<<endl;

    cout<<"Scorpian (Press 1 to choose)"<<endl;

    cout<<"Strength ***"<<endl;
    cout<<"Speed ***"<<endl;
    cout<<"Special move *****"<<endl<<endl<<endl;

    cout<<"Terminator (Press 2 to choose)"<<endl;

    cout<<"Strength *****"<<endl;
    cout<<"Speed **"<<endl;
    cout<<"Special move ****"<<endl<<endl<<endl;

    cout<<"Katana (Press 3 to choose)"<<endl;

    cout<<"Strength ***"<<endl;
    cout<<"Speed *****"<<endl;
    cout<<"Special move ***"<<endl<<endl<<endl;
    }

    cin>>choice1;

    if (choice1==1)
    {
    cout<<"You chose Scorpian!"<<endl;
    }

    if (choice1==2)
    {
    cout<<"You chose Terminator!"<<endl;
    }

    if (choice1==3)
    {
    cout<<"You chose Katana!"<<endl;
    }

    cout<<"1 is kick, 2 is punch, 3 is special move (when meter is full)"<<endl;

    cout<<"Opponent 1, Scarface"<<endl<<endl;
    cout<<"Begin!"<<endl;
    cin>>choice;


    for (x=0; x<4; x++)
    {
    if (choice==1)
    {


    switch (a)
    {
    case 0: cout<<"You have kicked ";
    break;
    }

    switch (b)
    {
    case 0: cout<<"and scored a direct hit"<<endl;
    break;

    case 1: cout<<"and have been blocked"<<endl;
    break;

    case 2: cout<<"and have been countered and the force of the blow has injured you"<<endl;

    }
    }


    }

    if (choice==2)
    {
    cout<<"You have punched "<<endl;
    }

    for (x=0; x<11; x++)
    {
    if ((choice==3)||(x>=5))
    {
    cout<<"You have unleashed your special move on your opponent "<<endl;
    }

    if ((choice==3)||(x<=4))
    {
    cout<<"You do not have enough energy to use your special move"<<endl;
    }
    }














    return 0;
    }

  12. #12
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I wrote that program template for you, try completing it, and post what do you get...
    Code:
    #include <iostream>
    #include <ctime>
    using namespace std;
    struct fighter{
    	int strength;
    	int speed;
    	int special;
    };
    
    int main()
    {
    	int choice;
    	fighter player;
    	cout<<"Welcome to Fight Arena!"<<endl<<endl;
    	cout<<"Please choose a fighter you wish to use"<<endl<<endl<<endl;
    
    	cout<<"Scorpian (Press 1 to choose)"<<endl;
    
    	cout<<"Strength ***"<<endl;
    	cout<<"Speed ***"<<endl;
    	cout<<"Special move *****"<<endl<<endl<<endl;
    
    	cout<<"Terminator (Press 2 to choose)"<<endl;
    
    	cout<<"Strength *****"<<endl;
    	cout<<"Speed **"<<endl;
    	cout<<"Special move ****"<<endl<<endl<<endl;
    
    	cout<<"Katana (Press 3 to choose)"<<endl;
    
    	cout<<"Strength ***"<<endl;
    	cout<<"Speed *****"<<endl;
    	cout<<"Special move ***"<<endl<<endl<<endl;
    
    	cin >> choice;
    	switch ( choice )
    	{
    	case 1:
    		player.special= 5;
    		player.speed=3;
    		player.strength=3;
    		break;
    	case 2:
    		//continue as above
    	case 3:
    		//continue as above
    	default :
    		break;
    		//you can choose either to creat a default player of display the options again
    	}
    	//The you creat the computer player
    	fighter computer;
    	//so select a random character to be the computer player
    	//then you start the battle
    	//you make the user choose a move and you choose a random move for the computer
    	cout<<"1 is kick, 2 is punch, 3 is special move (when meter is full)"<<endl;
    
    	cout<<"Opponent 1, Scarface"<<endl<<endl;
    	cout<<"Begin!"<<endl;
    	cin>>choice;
    	//use a switch statement to chech the user input
    	switch ( choice ){
    	case 1:
    		//decrease the health of the computer;
    		//continue with all the cases
    		break;
    	}
    
    	return 0;
    }
    Good luck...
    none...

  13. #13
    Registered User
    Join Date
    Jan 2003
    Posts
    15

    Thats for a ganme?

    That is for a game?

  14. #14
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953

    Re: Thats for a ganme?

    Originally posted by DAIALOS
    That is for a game?
    You can read the first post in this thread, read the text below the code, and you'll find the answer...
    none...

  15. #15
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    Posts
    1,401
    i dont want to seem like a party pooper, but i strongly advise against this sort of programming. its better to learn the basics of programming with simpler projects, and gradually build up a strong knowledge base, and a good idea of how to structure programs efficiently. ray, maybe you should do something else for your assignment, and continue this project when you're a little more familiar with c++.

    but if you're still intent on doing this project now, ammar's example isn't bad as a base. a good loop structure and some formulas for determining damage taken is all it needs. good luck.
    benforbes@optusnet.com.au
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ
    Tutorials

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Menu
    By Krush in forum C Programming
    Replies: 17
    Last Post: 09-01-2009, 03:34 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  3. Help with a pretty big C++ assignment
    By wakestudent988 in forum C++ Programming
    Replies: 1
    Last Post: 10-30-2006, 09:46 PM
  4. Replies: 1
    Last Post: 10-27-2006, 02:21 PM
  5. DirectX dll Final Debug and Final Retail
    By hdragon in forum Tech Board
    Replies: 0
    Last Post: 11-15-2005, 09:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21