........ed off at functions

This is a discussion on ........ed off at functions within the C++ Programming forums, part of the General Programming Boards category; ive been trying to wrok wih this one fucntion forever but ti doesnt like me! any help? PHP Code: #include <iostream> ...

  1. #1
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608

    ........ed off at functions

    ive been trying to wrok wih this one fucntion forever but ti doesnt like me! any help?
    PHP Code:
    #include <iostream>
    #include <string> 
    #include <stdlib.h> 
    #include <windows.h>
    #include <conio.h>
    #include <fstream>
    using namespace std;
    int menuscreen(int *goldint *healthint *magicint *attackint *aimint *defenceint *menuselectint *charactertypestring *weaponstring *shieldstring *armorstring *playerchar *empty, string *item1string *item2string *item3string *item4string *item5string *item6string *item7string *item8string *item9string *item10string *item11string *item12string *item13string *item14string *item15string *item16string *item17string *item18string *item19string *item20string *item21string *item22string *item23string *item24string *item25string *item26string *item27string *item28string *item29string *item30);
    char menuscreenv;
    int goldhealthmagicattackaimdefenceynvaricharactertype;
    string empty, weaponshieldarmorszWordszLineplayeritem1item2item3item4item5item6item7item8item9item10item11item12item13item14item15item16item17item18item19item20item21item22item23item24item25item26item27item28item29item30;
    bool menuselect;
    int main(int argcchar *argv[])
    {
    menu: empty = "empty";
    cin >> menuselect;
    if (
    menuselect == 1){
    textcolor(RED);
    clrscr();
    Sleep(1000);
           
    ifstream fin;
        
    fin.open("Stats.sav");
        if(
    fin.fail())
        {
            
    cout << "ERROR: Could not find Stats.sav!\n";
            
    system("pause");
            goto 
    menu;
        }

        
    cout << endl;
          
    fin.clear();

          
    fin >> szWord >> player;
        
    fin >> szWord >> charactertype;
        
    fin >> szWord >> health;
        
    fin >> szWord >> gold;
        
    fin >> szWord >> magic;
        
    fin >> szWord >> attack;
        
    fin >> szWord >> aim;
        
    fin >> szWord >> defence;
        
    fin >> szWord >> weapon;
        
    fin >> szWord >> shield;
        
    fin >> szWord >> armor;
        
    fin >> szWord >> item1;
        
    fin >> szWord >> item2;
        
    fin >> szWord >> item3;
        
    fin >> szWord >> item4;
        
    fin >> szWord >> item5;
        
    fin >> szWord >> item6;
        
    fin >> szWord >> item7;
        
    fin >> szWord >> item8;
        
    fin >> szWord >> item9;
        
    fin >> szWord >> item10;
        
    fin >> szWord >> item11;
        
    fin >> szWord >> item12;
        
    fin >> szWord >> item13;
        
    fin >> szWord >> item14;
        
    fin >> szWord >> item15;
        
    fin >> szWord >> item16;
        
    fin >> szWord >> item17;
        
    fin >> szWord >> item18;
        
    fin >> szWord >> item19;
        
    fin >> szWord >> item20;
        
    fin >> szWord >> item21;
        
    fin >> szWord >> item22;
        
    fin >> szWord >> item23;
        
    fin >> szWord >> item24;
        
    fin >> szWord >> item25;
        
    fin >> szWord >> item26;
        
    fin >> szWord >> item27;
        
    fin >> szWord >> item28;
        
    fin >> szWord >> item29;
        
    fin >> szWord >> item30;
        
    fin.close();
     
    cout << "Hello "<< player <<", Your game has been loaded..." << endl ;
    system("pause");
    }
    else if (
    menuselect == 2){
    textcolor(RED);
    clrscr();
    Sleep(1000);
    cout << "note: there can only be one game saved, making a new game will overwrite" << endl << "previous one" << endl ;
    cout << "If you still would like to create a new game press 1, if no press 2" << endl;
    cin >> ynvari;
    if (
    ynvari == 2)
     goto 
    menu;
    cout << "Choose your characters name." << endl ;
    cin >> player ;
    cout << "Choose what kind of character to be." << endl ;
    cout << "1. Mage 2. Barbarian 3. Warrior 4. Archer" << endl ;
    cin >> charactertype ;
    switch( 
    charactertype )
    {
            case 
    1:    //Mage
            
    magic=60;
            
    attack=3;
            
    aim=7;
            
    defence=9;
            
    item1 "wizardybook";
            
    item2 "basicstaff";
            
    item3 "robe";
            
    item4 "manapotion";
                             break;

            case 
    2:     //Barbarian
            
    magic=9;
            
    attack=13;
            
    aim=13;
            
    defence=11;
            
    item1="dagger";
            
    item2="mediumsword";
            
    item3="bronzesmallshield";
            
    item4="bronzeplatewh";
                           break;

            case 
    3:     //Warrior
            
    magic=9;
            
    attack=13;
            
    aim=13;
            
    defence=11;
            
    item1="dagger";
            
    item2="mediumsword";
            
    item3="bronzesmallshield";
            
    item4="bronzeplatewh";
                           break;

            case 
    4:    //Archer
            
    magic=9;
            
    attack=12;
            
    aim=16;
            
    defence=11;
            
    item1="dagger";
            
    item2="arrows";
            
    item3="leathercloths";
            
    item4="bow";
                           break;

    default:
       break;
    }        
    // end charactertype
    gold=75;
    health=100;
    item5="hppotion";
    item6="hppotion";
    item7="hppotion";
    item8="hppotion";
    item9="hppotion";
    item10=empty;
    item11=empty;
    item12=empty;
    item13=empty;
    item14=empty;
    item15=empty;
    item16=empty;
    item17=empty;
    item18=empty;
    item19=empty;
    item20=empty;
    item21=empty;
    item22=empty;
    item23=empty;
    item24=empty;
    item25=empty;
    item26=empty;
    item27=empty;
    item28=empty;
    item29=empty;
    item30=empty;
    weapon=empty;
    shield=empty;
    armor=empty;
      
    // finishes off item varibles and starts writing to stats.sav

    ofstream fout;
        
    fout.open("stats.sav");
        
    fout << "Player: " << player << " ";
        
    fout << "CharacterType: " << charactertype << " ";
         
    fout << "Health: " << health << " ";
        
    fout << "Gold: "   << gold   << " ";
        
    fout << "Magic: "  << magic   << " ";
        
    fout << "Attack: " << attack   << " ";
        
    fout << "Aim: "    << aim   << " ";
        
    fout << "Defence: "<< defence   << " ";
        
    fout << "Weapon: "   << weapon << " ";
        
    fout << "Shield: "   << shield << " ";
        
    fout << "Armor: "   << armor << " ";
        
    fout << "Item1: " << item1 << " ";
        
    fout << "Item2: " << item2 << " ";
        
    fout << "Item3: " << item3 << " ";
        
    fout << "Item4: " << item4 << " ";
        
    fout << "Item5: " << item5 << " ";
        
    fout << "Item6: " << item6 << " ";
        
    fout << "Item7: " << item7 << " ";
        
    fout << "Item8: " << item8 << " ";
        
    fout << "Item9: " << item9 << " ";
        
    fout << "Item10: " << item10 << " ";
        
    fout << "Item11: " << item11 << " ";
        
    fout << "Item12: " << item12 << " ";
        
    fout << "Item13: " << item13 << " ";
        
    fout << "Item14: " << item14 << " ";
        
    fout << "Item15: " << item15 << " ";
        
    fout << "Item16: " << item16 << " ";
        
    fout << "Item17: " << item17 << " ";
        
    fout << "Item18: " << item18 << " ";
        
    fout << "Item19: " << item19 << " ";
        
    fout << "Item20: " << item20 << " ";
        
    fout << "Item21: " << item21 << " ";
        
    fout << "Item22: " << item22 << " ";
        
    fout << "Item23: " << item23 << " ";
        
    fout << "Item24: " << item24 << " ";
        
    fout << "Item25: " << item25 << " ";
        
    fout << "Item26: " << item26 << " ";
        
    fout << "Item27: " << item27 << " ";
        
    fout << "Item28: " << item28 << " ";
        
    fout << "Item29: " << item29 << " ";
        
    fout << "Item30: " << item30 << " ";
            
    fout.close();
    cout << "goto continue game from the menu to start a game with your new status" << endl;
    system("pause");
    goto 
    menu;
    }
    else if (
    menuselect == 3){
       
    //Something
    goto menu;
    }
    else if (
    menuselect == 4){
      return 
    0;
    }
    else {
    textcolor(WHITE);
    clrscr();
    cout << "invalid input... input 1, 2, 3, or 4." << endl;
    cout << "Returning to Menu....." << endl;
    Sleep(5500);
    goto 
    menu;
    }
    if (
    charactertype == 1)
    menuscreenv "&&&&&&&&&&&-MENU-&&&&&&&&&&&&&&                   *\n&                             &                    **\n&  1. Resume Game             &                     ****\n&                             &       ****          *******\n&                             &      *    *       *********\n&  2. Save Game               &      *    *     *************\n&                             &       ****     *****************\n&                             &        **        ##############\n&  3. View Status             &        **       ####   ##   ####\n&                             &        **      #####   ##   #####\n&                             &        **      #####   ##   #####\n&  4. View Map                &        **       ################\n&                             &        **        ##############\n&                             &        **         ############\n&  5. Go to Main Screen       &        **      %%%%%%%%%%%%%%%%%%%\n&                             &        **     %%%%%%%%%%%%%%%%%%%%%\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&        **   %%%%%%%%%%%%%%%%%%%%%%%%\n";
    else if (
    charactertype == 2)
    menuscreenv "&&&&&&&&&&&-MENU-&&&&&&&&&&&&&&  <<<<<<<>>>>>>>>&&&&&&\n&                             & <<<<<<<<>>>>>>>>>&&&&&&\n&  1. Resume Game             & <<<<<<<<>>>>>>>>>&&  &&&\n&                             &  <<<<<<<>>>>>>>>&&&  &&&\n&                             &        |||   &&&&&&&&&&&\n&  2. Save Game               &        |||   &&&&&&&&&&&\n&                             &      %%|||%%  &&&&&&&&&   %%%%%\n&                             &      eeeeeee%%%%%%%%%%%%%%%%%%%%%\n&  3. View Status             &      eeeeeee%%%%%%%%%%%%%%%%%%%%%\n&                             &      eeeeeee%%%%%%%%%%%%%%%%%%%%e\n&                             &        |||%%%%%%%%%%%%%%%%%%%%eee\n&  4. View Map                &        |||%%%%%%%%%%%%%%%%%%%eeeee\n&                             &        |||%%%%%%%%%%%%%%%%%%eeeeeee\n&                             &        |||%%%%%%%%%%%%%%%%%%eeeeeee\n&  5. Go to Main Screen       &        |||%%%%%%%%%%%%%%%%%%%eeeeee\n&                             &        |||%%%%%%%%%%%%%%%%%%% eeee\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&        |||%%%%%%%%%%%%%%%%%%  eeee";
    else if (
    charactertype == 3)
    menuscreenv "&&&&&&&&&&&-MENU-&&&&&&&&&&&&&&                !\n&                             &            &&&&!!&&&&\n&  1. Resume Game             &           &&&&&!!&&&&&\n&                             &          &&&&&&!!!&&&&&\n&                             &         &&&&& &!!! &&&&&\n&  2. Save Game               &         &&&&   !!!  &&&&\n&                             &         &&&&& &!!! &&&&&\n&                             &         &&&&&&&!!!&&&&&&\n&  3. View Status             &          &&&&&&!!!&&&&&\n&                             &           &&&&&!!!&&&&\n&                             &        %%%%%%%%!!!%%%%%%%\n&  4. View Map                &       %%%%%%%%%!!!%%%%%%%%\n&                             &     %%%%%%%%%%%!!!%%%%%%%%%\n&                             &    %%%%%^%%%%%%!!!%%%%%^%%%%\n&  5. Go to Main Screen       &   %%%%%%^%%%%%%!!!%%%%%^%%%%%\n&                             &  %%%%%%%^%%%%%%!!!%%%%%^%%%%%%\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&    %%%%%%^%%%%!!!!!%%%^%%%%%%";
    else if (
    charactertype == 4)
    menuscreenv "&&&&&&&&&&&-MENU-&&&&&&&&&&&&&&                   &&&&&&&&\n&                             &                  &&&&&&&&&&\n&                             &                  &&   &   &\n&  1. Resume Game             &                  &&  &&&  &\n&                             &                  &&&&&&&&&&\n&                             &                  &&&&&&&&&&\n&  2. Save Game               &                   &&&&&&&&\n&                             &              %%%%%%%%%%%%%%%%%%\n&                             &             ^^^%%%%%%%%%%%%%%^^^\n&  3. View Status             &            %%^^^^%%%%,-%^^^^%^^^^\n&                             &            %%%^^^^%%/%%/^^^^^%^^^^\n&                             &            %%%%^^^^/%%///%^^^^%^^^^\n&  4. View Map                &            %%%%%^^^^%///%%%%^^^^^^^^\n&                             &            %%%%%^^^^^^/%%%%%%^^^^^^^\n&                             &            %%%%%/^^^^^^%%%%%%%^^^^^\n&  5. Go to Main Screen       &            %%%%/%%///%%%%%%%%%%%\n&                             &            %%%/%%///%%%%%%%%%%%%\n&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&              /%%///%%%%%%%%%%%%";
    int menuscreen(&gold, &health, &magic, &attack, &aim, &defence, &menuselect, &charactertype, &weapon, &shield, &armor, &player, &empty, &item1, &item2, &item3, &item4, &item5, &item6, &item7, &item8, &item9, &item10, &item11, &item12, &item13, &item14, &item15, &item16, &item17, &item18, &item19, &item20, &item21, &item22, &item23, &item24, &item25, &item26, &item27, &item28, &item29, &item30);
      goto 
    menu;
       
    cin.get();
       return 
    0;
    }

    int menuscreen(int *goldint *healthint *magicint *attackint *aimint *defenceint *menuselectint *charactertypestring *weaponstring *shieldstring *armorstring *playerchar *empty, string *item1string *item2string *item3string *item4string *item5string *item6string *item7string *item8string *item9string *item10string *item11string *item12string *item13string *item14string *item15string *item16string *item17string *item18string *item19string *item20string *item21string *item22string *item23string *item24string *item25string *item26string *item27string *item28string *item29string *item30){
    cout << menuscreenv << endl;
    cin >> menuselect;
    if (
    menuscreen == 1){
    }
    else if (
    menuscreen == 2){
    ofstream fout;
        
    fout.open("stats.sav");
        
    fout << "Player: " << player << " ";
        
    fout << "CharacterType: " << charactertype << " ";
         
    fout << "Health: " << health << " ";
        
    fout << "Gold: "   << gold   << " ";
        
    fout << "Magic: "  << magic   << " ";
        
    fout << "Attack: " << attack   << " ";
        
    fout << "Aim: "    << aim   << " ";
        
    fout << "Defence: "<< defence   << " ";
        
    fout << "Weapon: "   << weapon << " ";
        
    fout << "Shield: "   << shield << " ";
        
    fout << "Armor: "   << armor << " ";
        
    fout << "Item1: " << item1 << " ";
        
    fout << "Item2: " << item2 << " ";
        
    fout << "Item3: " << item3 << " ";
        
    fout << "Item4: " << item4 << " ";
        
    fout << "Item5: " << item5 << " ";
        
    fout << "Item6: " << item6 << " ";
        
    fout << "Item7: " << item7 << " ";
        
    fout << "Item8: " << item8 << " ";
        
    fout << "Item9: " << item9 << " ";
        
    fout << "Item10: " << item10 << " ";
        
    fout << "Item11: " << item11 << " ";
        
    fout << "Item12: " << item12 << " ";
        
    fout << "Item13: " << item13 << " ";
        
    fout << "Item14: " << item14 << " ";
        
    fout << "Item15: " << item15 << " ";
        
    fout << "Item16: " << item16 << " ";
        
    fout << "Item17: " << item17 << " ";
        
    fout << "Item18: " << item18 << " ";
        
    fout << "Item19: " << item19 << " ";
        
    fout << "Item20: " << item20 << " ";
        
    fout << "Item21: " << item21 << " ";
        
    fout << "Item22: " << item22 << " ";
        
    fout << "Item23: " << item23 << " ";
        
    fout << "Item24: " << item24 << " ";
        
    fout << "Item25: " << item25 << " ";
        
    fout << "Item26: " << item26 << " ";
        
    fout << "Item27: " << item27 << " ";
        
    fout << "Item28: " << item28 << " ";
        
    fout << "Item29: " << item29 << " ";
        
    fout << "Item30: " << item30 << " ";
            
    fout.close();
    }
    else if (
    menuscreen == 3){
    }
    else if (
    menuscreen == 4){
    }
    else if (
    menuscreen == 5){
    }

    i tried to cut out the extra stuff. what im trying to do is have variables named in main be tranferable between them so they both can write to a variable and read it. (as the same thing)

    ignore blank ifstatements and gotos im gonna deal with those later. thanks in advance
    Last edited by Klinerr1; 07-29-2002 at 01:12 PM.
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  2. #2
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    dude, you got way to many arguments on that function

    and can you explain what problem you are having with it? It's hard to look for something wrong if you don't tell us what IS wrong.

  3. #3
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    i said it. i need variables that are named in main to be the same as in menuscreen. but i decided to work around it though. i am gonna make it a header file (menuscreen.cpp) and see if i cant do soemthign better
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    DO NOT use bad language in any part of your posts. It's rude. There are people on this board who may be offended by your bad mouth, so please do not swear.

    Ultimately the reason why you're having trouble is that your functions are just crazy, and your code is a mess!!!

    Why have you got separate variables for item1 -> item30?? Haven't you heard of arrays before??

    and use CODE tags instead of PHP tags. it make things easier to read.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  5. #5
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    a) wheres bad language b) oh, most peopel like php
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    Are you stupid or something??

    Take a look at the name of the thread you started. That's where the bad language is.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  7. #7
    Sir Mister Insane Sako Klinerr1's Avatar
    Join Date
    May 2002
    Posts
    608
    oooooooooooooohhhhhhhhhh- my bad. yeah I guess im stupid or something. I was in a bad mood that day. (look no typos) im trying my best to "not ruin the boards" (see my debugger post http://www.cprogramming.com/cboard/s...threadid=22543 )
    Email: Klinerr1@nc.rr.com || AIM: MisterSako || MSN: sakotheinsane@hotmail.com

    -the shroom has spoken

  8. #8
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    my suggestion is to make the variables all global. You don't need a header....personally i've found that seperating things into headers in debugging stages is very very annoying...it's hard to visualize everything if you have to keep opening up different documetns.
    PHP and XML
    Let's talk about SAX

  9. #9
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    you sound more like that MadTaco dude everytime you post

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Functions and Classes - What did I do wrong?
    By redmage in forum C++ Programming
    Replies: 5
    Last Post: 04-11-2005, 12:50 PM
  2. calling functions within functions
    By edd1986 in forum C Programming
    Replies: 3
    Last Post: 03-29-2005, 03:35 AM
  3. Factory Functions HOWTO
    By GuardianDevil in forum Windows Programming
    Replies: 1
    Last Post: 05-01-2004, 02:41 PM
  4. Shell functions on Win XP
    By geek@02 in forum Windows Programming
    Replies: 6
    Last Post: 04-19-2004, 06:39 AM
  5. functions - please help!!!!
    By linkies in forum C Programming
    Replies: 1
    Last Post: 08-21-2002, 08:53 AM

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