function call not working

This is a discussion on function call not working within the C++ Programming forums, part of the General Programming Boards category; Code: #include<iostream> #include<conio.h> #include<string> #define noattack(); #define stats(); using namespace std; using std::cout; using std::endl; int main() { string pname; ...

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    function call not working

    Code:
    #include<iostream>
    #include<conio.h>
    #include<string>
    
    #define noattack();
    #define stats();
    
    using namespace std;
    
    using std::cout;
    using std::endl;
    
    int main()
    {
    string pname;
    char choice;
    char attack;
    int phealth = 100;
    int gold = 0;
    int items = 0;
    int exp = 0;
    int magic = 0;
    int level = 1;
    int size;
    int x;
    stats();
    void shop();
    noattack();
    
    if (exp == 3)
    {
    level=+1;
    cout << "You have gained a level!!\n" << endl;
    }
    
    else if (exp == 6)
    {
    level=+1;
    cout << "You have gained another level!!\n" << endl;
    }
    
    else if (exp == 9)
    {
    level=+1;
    cout << "You have reached another level!!\n" << endl;
    }
    
    else if (exp == 12)
    {
    level=+1;
    cout << "You have reached a higher level!\n" << endl;
    }
    
    else if (exp == 15)
    {
    level=+1;
    cout << "You are at a strong level!\n" << endl;
    }
    
    else if (exp == 18)
    {
    level=+1;
    cout << "You are almost at the highest level!\n" << endl;
    }
    
    else if (exp == 21)
    {
    level=+1;
    cout << "You just keep getting stronger... new level reached!\n" << endl;
    }
    
    else if (exp == 24)
    {
    level=+1;
    cout << "Penultimate level reached!!\n" << endl;
    }
    
    else if (exp == 27)
    {
    level=+1;
    cout << "You are at the maxuim level!\n" << endl;
    }
    
    if (phealth <0)
    {
    system("cls");
    char sentgo[]="As you are struck, you fall to the floor...\n" 
                  "all of the hope for a peacful return to Faucet\n"
                  "Is lost...\n"
                  "\n\n"
                  "G  A  M  E   O  V  E  R ! ! !\n"
                  "\n\n";
     size=strlen(sentgo);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgo[x]);
        }
        Sleep(3000);
        exit(0);
    
    }
    
    main:
    system("cls");
    
    printf("\t\t|__________________________________________|\n"
           "\t\t|           DAISY'S QUEST                  |\n"
           "\t\t|          ===============                 |\n"
           "\t\t|                                          |\n"
           "\t\t|       Programed By Peter Watts           |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press P to Play                    |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press C to View Credits            |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press Q to Quit                    |\n"
           "\t\t|__________________________________________|\n");
           cout << "\n\n";
           cout << "Selection: " << endl;
           cin >> choice;
           
           if (choice == 'q')
           {
           system("cls");
           char sentgq[]="Daisy hopes to see you again  real soon...\n"
                         "\n\n";
                         size=strlen(sentgq);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgq[x]);
        }
        Sleep(2000);
        exit(0);
        }
        
        else if (choice == 'c')
        {
        system("cls");
        char sentgc[]="\n\n"
                      "\t\tD A I S Y 'S   Q U E S T\n"
                      "\n\n"
                      "Programed and written by Peter Watts\n"
                      "\n\n"
                      "Based on the idea of Mario Bros.\n"
                      "\n\n"
                      "Game made in all of five months!\n"
                      "\n\n"
                      "Thanks for playing this game, as I know text games can\n"
                      "\n\n"
                      "be pretty dull...\n"
                      "\n\n"
                      "Look out for the sequal soon!!\n"
                      "\n\n"
                      "\t\tF  I  N\n"
                      "\n\n";
                      size=strlen(sentgc);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgc[x]);
        }
        Sleep(2000);
        system("cls");
        goto main;
        system("cls");
        }
        
        else if (choice == 'p')
        {
        system("cls");
        char senta[]="Hail there adventurer!\n"
                     "\n\n"
                     "I want to ask you three questions\n"
                     "\n\n"
                     "1: Do you seek fame and fortune?\n"
                     "\n\n"
                     "2: Do you want to help out a poor princess?\n"
                     "\n\n"
                     "3: Do you want the title of a true hero?\n"
                     "\n\n"
                     "I know all the answers to these is YES!\n";
                     
        size=strlen(senta);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",senta[x]);
        }
        Sleep(2000);
        
        system("cls");
        char sentb[]="My name is Princess Daisy..\n"
                     "\n\n"
                     "But, I can't keep calling you adventurer\n"
                     "\n\n"
                     "now can I? So, Sir / Madame, what is your name?\n"
                     "\n\n";
                     size=strlen(sentb);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentb[x]);
        }
        cout << "My name is: " << pname;
        cin >> pname;
        Sleep(1000);
        system("cls");
        cout << "So, you are called " << pname;
        cout << "\n\n";
        char sentc[]="Nice to meet you.\n"
                     "\n\n"
                     "I need your assistance....\n"
                     "\n\n"
                     "My kingdom of Sarahasland is in terrible danger..\n"
                     "\n\n"
                     "I have to get to the castle to speak to my sister,\n"
                     "\n\n"
                     "Princess Peach.  But, I can't leave my loyal subjects...\n"
                     "\n\n"
                     "Will you go in my place?  Y/N:\n"
                     "\n\n";
                     size=strlen(sentc);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentc[x]);
        }
        cout << "Will you go? " << endl;
        cin >> choice;
        
        if (choice == 'n')
        {
        system("cls");
        char sentwg[]="I am sorry that I called on your help..\n"
                      "\n\n"
                      "My land is now sure to collapse in the face\n"
                      "\n\n"
                      "of eternal hell\n"
                      "\n\n"
                      "YOU  HAVE  TAKEN  THE  COWARDS  WAY  OUT\n"
                      "\n\n";
                      size=strlen(sentwg);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentwg[x]);
        }
        Sleep(2000);
        exit(0);
        }
        
        else if (choice == 'y')
        {
        system("cls");
        items=+1; //1 items total
        char sentig[]="I thank you kind one.  Here, I give you a LETTER.\n"
                      "\n\n"
                      "You can use it to enter the village.\n"
                      "\n\n"
                      "Well, good luck kind one, I wish you all the best...\n"
                      "\n\n"
                      "What will you do now?\n"
                      "\n\n"
                      "Press E to explore the surrounding area\n"
                      "\n\n"
                      "Press A to attack\n"
                      "\n\n"
                      "Press S to view your stats\n"
                      "\n\n";
                      size=strlen(sentig);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentig[x]);
        }
        cout << "Choice?: " << endl;
        cin >> choice;
        }
        
        if (choice == 'a') 
        {
        noattack()
        }
        else if (choice == 's')
        {
        stats()
        }
        
    noattack();
    {
    system("cls");
    cout << "There is nobody to attack\n" << endl;
    return 0;
    }
    
    stats();
    {
    cout << "\t\tSTATUS SCREEN\n";
    cout << "\n\n";
    cout << "Player Name " << pname;
    cout << "\n\n";
    cout << "Level is at " << level;
    cout << "\n\n";
    cout << "Experience " << exp;
    cout << "\n\n";
    cout << "Items totl " << items;
    cout << "\n\n";
    cout << "Magic levl " << magic;
    cout << "\n\n";
    cout << "Gold found " << gold;
    cout << "\n\n";
    cout << "Health is  " << phealth;
    cout << "\n\n";
    cout << "Press a key to exit" << endl;
        getch();
            }
        
    
    
    }
    return 0;
    } // end of function
    why is the function of stats not working, as it comiles ok without errors, when I go to press S, it just quits the program without viewing the stats

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    #define noattack();
    #define stats();

    I don't know what you want these things to do, but I can almost guarantee you that they don't do what you think. I wonder if it's even legal syntax.

    In general, you have a lot of syntax errors in there.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    That is some intresting code....
    1: You have ";" at the end of your function names.
    2: You should put your stuff in your little main: into the actual main() function.
    Here is a quick layout of how it should go
    Code:
    #include <iostream>
    #include <string>
    
    using namespace std;//If you do this you don't have to put using std::cout, etc
    
    void noAttack();    //This is how you prototype a function
    void stats();       
    
    int main()
    {
        //set up the variables you want
        //put all of your welcome code here etc
        //or make a start function whatever floats your boat
        
        stats();    //this is how you would call the function
    }
    
    void noAttack()
    {
        //noAttack() code here
    }
    
    void stats()
    {
        //stats stuff here
    }
    Also spaces are nice.
    Woop?

  4. #4
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    here now fix the three funcs up at the top and should be ok. also do something about the goto. learn about loops instead.
    Code:
    #include<iostream>
    #include<conio.h>
    #include<string>
    #include<windows.h>
    
    void noattack();
    void stats();
    void shop();
    
    void noattack()
    {
       // put stuff here for noattack
    }
    
    void stats()
    {
       // do your stats
    }
    
    void shop()
    {
       // do shopping
    }
    
    
    using namespace std;
    
    using std::cout;
    using std::endl;
    
    int main()
    {
    string pname;
    char choice;
    char attack;
    int phealth = 100;
    int gold = 0;
    int items = 0;
    int exp = 0;
    int magic = 0;
    int level = 1;
    int size;
    int x;
    stats();
    shop();
    noattack();
    
    if (exp == 3)
    {
    level=+1;
    cout << "You have gained a level!!\n" << endl;
    }
    
    else if (exp == 6)
    {
    level=+1;
    cout << "You have gained another level!!\n" << endl;
    }
    
    else if (exp == 9)
    {
    level=+1;
    cout << "You have reached another level!!\n" << endl;
    }
    
    else if (exp == 12)
    {
    level=+1;
    cout << "You have reached a higher level!\n" << endl;
    }
    
    else if (exp == 15)
    {
    level=+1;
    cout << "You are at a strong level!\n" << endl;
    }
    
    else if (exp == 18)
    {
    level=+1;
    cout << "You are almost at the highest level!\n" << endl;
    }
    
    else if (exp == 21)
    {
    level=+1;
    cout << "You just keep getting stronger... new level reached!\n" << endl;
    }
    
    else if (exp == 24)
    {
    level=+1;
    cout << "Penultimate level reached!!\n" << endl;
    }
    
    else if (exp == 27)
    {
    level=+1;
    cout << "You are at the maximum level!\n" << endl;
    }
    
    if (phealth <0)
    {
    system("cls");
    char sentgo[]="As you are struck, you fall to the floor...\n" 
                  "all of the hope for a peacful return to Faucet\n"
                  "Is lost...\n"
                  "\n\n"
                  "G  A  M  E   O  V  E  R ! ! !\n"
                  "\n\n";
     size=strlen(sentgo);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgo[x]);
        }
        Sleep(3000);
        exit(0);
    
    }
    
    main:
    system("cls");
    
    printf("\t\t|__________________________________________|\n  "
           "\t\t|           DAISY'S QUEST                  |\n"
           "\t\t|          ===============                 |\n"
           "\t\t|                                          |\n"
           "\t\t|       Programed By Peter Watts           |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press P to Play                    |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press C to View Credits            |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press Q to Quit                    |\n"
           "\t\t|__________________________________________|\n  ");
           cout << "\n\n";
           cout << "Selection: " << endl;
           cin >> choice;
           
           if (choice == 'q')
           {
           system("cls");
           char sentgq[]="Daisy hopes to see you again  real soon...\n"
                         "\n\n";
                         size=strlen(sentgq);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgq[x]);
        }
        Sleep(2000);
        exit(0);
        }
        
        else if (choice == 'c')
        {
        system("cls");
        char sentgc[]="\n\n"
                      "\t\tD A I S Y 'S   Q U E S T\n"
                      "\n\n"
                      "Programed and written by Peter Watts\n"
                      "\n\n"
                      "Based on the idea of Mario Bros.\n"
                      "\n\n"
                      "Game made in all of five months!\n"
                      "\n\n"
                      "Thanks for playing this game, as I know text games can\n"
                      "\n\n"
                      "be pretty dull...\n"
                      "\n\n"
                      "Look out for the sequal soon!!\n"
                      "\n\n"
                      "\t\tF  I  N\n"
                      "\n\n";
                      size=strlen(sentgc);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgc[x]);
        }
        Sleep(2000);
        system("cls");
        goto main;
        system("cls");
        }
        
        else if (choice == 'p')
        {
        system("cls");
        char senta[]="Hail there adventurer!\n"
                     "\n\n"
                     "I want to ask you three questions\n"
                     "\n\n"
                     "1: Do you seek fame and fortune?\n"
                     "\n\n"
                     "2: Do you want to help out a poor princess?\n"
                     "\n\n"
                     "3: Do you want the title of a true hero?\n"
                     "\n\n"
                     "I know all the answers to these is YES!\n";
                     
        size=strlen(senta);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",senta[x]);
        }
        Sleep(2000);
        
        system("cls");
        char sentb[]="My name is Princess Daisy..\n"
                     "\n\n"
                     "But, I can't keep calling you adventurer\n"
                     "\n\n"
                     "now can I? So, Sir / Madame, what is your name?\n"
                     "\n\n";
                     size=strlen(sentb);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentb[x]);
        }
        cout << "My name is: " << pname;
        cin >> pname;
        Sleep(1000);
        system("cls");
        cout << "So, you are called " << pname;
        cout << "\n\n";
        char sentc[]="Nice to meet you.\n"
                     "\n\n"
                     "I need your assistance....\n"
                     "\n\n"
                     "My kingdom of Sarahasland is in terrible danger..\n"
                     "\n\n"
                     "I have to get to the castle to speak to my sister,\n"
                     "\n\n"
                     "Princess Peach.  But, I can't leave my loyal subjects...\n"
                     "\n\n"
                     "Will you go in my place?  Y/N:\n"
                     "\n\n";
                     size=strlen(sentc);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentc[x]);
        }
        cout << "Will you go? " << endl;
        cin >> choice;
        
        if (choice == 'n')
        {
        system("cls");
        char sentwg[]="I am sorry that I called on your help..\n"
                      "\n\n"
                      "My land is now sure to collapse in the face\n"
                      "\n\n"
                      "of eternal hell\n"
                      "\n\n"
                      "YOU  HAVE  TAKEN  THE  COWARDS  WAY  OUT\n"
                      "\n\n";
                      size=strlen(sentwg);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentwg[x]);
        }
        Sleep(2000);
        exit(0);
        }
        
        else if (choice == 'y')
        {
        system("cls");
        items=+1; //1 items total
        char sentig[]="I thank you kind one.  Here, I give you a LETTER.\n"
                      "\n\n"
                      "You can use it to enter the village.\n"
                      "\n\n"
                      "Well, good luck kind one, I wish you all the best...\n"
                      "\n\n"
                      "What will you do now?\n"
                      "\n\n"
                      "Press E to explore the surrounding area\n"
                      "\n\n"
                      "Press A to attack\n"
                      "\n\n"
                      "Press S to view your stats\n"
                      "\n\n";
                      size=strlen(sentig);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentig[x]);
        }
        cout << "Choice?: " << endl;
        cin >> choice;
        }
        
        if (choice == 'a') 
        {
        noattack();
        }
        else if (choice == 's')
        {
        stats();
        }
        
    noattack();
    {
    system("cls");
    cout << "There is nobody to attack\n" << endl;
    return 0;
    }
    
    stats();
    {
    cout << "\t\tSTATUS SCREEN\n";
    cout << "\n\n";
    cout << "Player Name " << pname;
    cout << "\n\n";
    cout << "Level is at " << level;
    cout << "\n\n";
    cout << "Experience " << exp;
    cout << "\n\n";
    cout << "Items totl " << items;
    cout << "\n\n";
    cout << "Magic levl " << magic;
    cout << "\n\n";
    cout << "Gold found " << gold;
    cout << "\n\n";
    cout << "Health is  " << phealth;
    cout << "\n\n";
    cout << "Press a key to exit" << endl;
        getch();
            }
        
    
    
    }
    return 0;
    } // end of function
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  5. #5
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    Why prototype them if they are above main
    Woop?

  6. #6
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    Still problems

    I did all you guys said, compiled it and got 2 linker errors saying

    undefined refrence to stats
    undefined refrence to noattac
    new code:

    Code:
    #include<iostream>
    #include<conio.h>
    #include<string>
    #include<windows.h>
    
    using namespace std;
    
    
    
    int main()
    {
    
    void stats();
    void noattack();
    string pname;
    char choice;
    char attack;
    int phealth = 100;
    int gold = 0;
    int items = 0;
    int exp = 0;
    int magic = 0;
    int level = 1;
    int size;
    int x;
    
    if (exp == 3)
    {
    level=+1;
    cout << "You have gained a level!!\n" << endl;
    }
    
    else if (exp == 6)
    {
    level=+1;
    cout << "You have gained another level!!\n" << endl;
    }
    
    else if (exp == 9)
    {
    level=+1;
    cout << "You have reached another level!!\n" << endl;
    }
    
    else if (exp == 12)
    {
    level=+1;
    cout << "You have reached a higher level!\n" << endl;
    }
    
    else if (exp == 15)
    {
    level=+1;
    cout << "You are at a strong level!\n" << endl;
    }
    
    else if (exp == 18)
    {
    level=+1;
    cout << "You are almost at the highest level!\n" << endl;
    }
    
    else if (exp == 21)
    {
    level=+1;
    cout << "You just keep getting stronger... new level reached!\n" << endl;
    }
    
    else if (exp == 24)
    {
    level=+1;
    cout << "Penultimate level reached!!\n" << endl;
    }
    
    else if (exp == 27)
    {
    level=+1;
    cout << "You are at the maxuim level!\n" << endl;
    }
    
    if (phealth <0)
    {
    system("cls");
    char sentgo[]="As you are struck, you fall to the floor...\n" 
                  "all of the hope for a peacful return to Faucet\n"
                  "Is lost...\n"
                  "\n\n"
                  "G  A  M  E   O  V  E  R ! ! !\n"
                  "\n\n";
     size=strlen(sentgo);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgo[x]);
        }
        Sleep(3000);
        exit(0);
    
    }
    
    main:
    system("cls");
    
    printf("\t\t|__________________________________________|\n"
           "\t\t|           DAISY'S QUEST                  |\n"
           "\t\t|          ===============                 |\n"
           "\t\t|                                          |\n"
           "\t\t|       Programed By Peter Watts           |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press P to Play                    |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press C to View Credits            |\n"
           "\t\t|                                          |\n"
           "\t\t|       Press Q to Quit                    |\n"
           "\t\t|__________________________________________|\n");
           cout << "\n\n";
           cout << "Selection: " << endl;
           cin >> choice;
           
           if (choice == 'q')
           {
           system("cls");
           char sentgq[]="Daisy hopes to see you again  real soon...\n"
                         "\n\n";
                         size=strlen(sentgq);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgq[x]);
        }
        Sleep(2000);
        exit(0);
        }
        
        else if (choice == 'c')
        {
        system("cls");
        char sentgc[]="\n\n"
                      "\t\tD A I S Y 'S   Q U E S T\n"
                      "\n\n"
                      "Programed and written by Peter Watts\n"
                      "\n\n"
                      "Based on the idea of Mario Bros.\n"
                      "\n\n"
                      "Game made in all of five months!\n"
                      "\n\n"
                      "Thanks for playing this game, as I know text games can\n"
                      "\n\n"
                      "be pretty dull...\n"
                      "\n\n"
                      "Look out for the sequal soon!!\n"
                      "\n\n"
                      "\t\tF  I  N\n"
                      "\n\n";
                      size=strlen(sentgc);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentgc[x]);
        }
        Sleep(2000);
        system("cls");
        goto main;
        system("cls");
        }
        
        else if (choice == 'p')
        {
        system("cls");
        char senta[]="Hail there adventurer!\n"
                     "\n\n"
                     "I want to ask you three questions\n"
                     "\n\n"
                     "1: Do you seek fame and fortune?\n"
                     "\n\n"
                     "2: Do you want to help out a poor princess?\n"
                     "\n\n"
                     "3: Do you want the title of a true hero?\n"
                     "\n\n"
                     "I know all the answers to these is YES!\n";
                     
        size=strlen(senta);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",senta[x]);
        }
        Sleep(2000);
        
        system("cls");
        char sentb[]="My name is Princess Daisy..\n"
                     "\n\n"
                     "But, I can't keep calling you adventurer\n"
                     "\n\n"
                     "now can I? So, Sir / Madame, what is your name?\n"
                     "\n\n";
                     size=strlen(sentb);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentb[x]);
        }
        cout << "My name is: " << pname;
        cin >> pname;
        Sleep(1000);
        system("cls");
        cout << "So, you are called " << pname;
        cout << "\n\n";
        char sentc[]="Nice to meet you.\n"
                     "\n\n"
                     "I need your assistance....\n"
                     "\n\n"
                     "My kingdom of Sarahasland is in terrible danger..\n"
                     "\n\n"
                     "I have to get to the castle to speak to my sister,\n"
                     "\n\n"
                     "Princess Peach.  But, I can't leave my loyal subjects...\n"
                     "\n\n"
                     "Will you go in my place?  Y/N:\n"
                     "\n\n";
                     size=strlen(sentc);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentc[x]);
        }
        cout << "Will you go? " << endl;
        cin >> choice;
        
        if (choice == 'n')
        {
        system("cls");
        char sentwg[]="I am sorry that I called on your help..\n"
                      "\n\n"
                      "My land is now sure to collapse in the face\n"
                      "\n\n"
                      "of eternal hell\n"
                      "\n\n"
                      "YOU  HAVE  TAKEN  THE  COWARDS  WAY  OUT\n"
                      "\n\n";
                      size=strlen(sentwg);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentwg[x]);
        }
        Sleep(2000);
        exit(0);
        }
        
        else if (choice == 'y')
        {
        system("cls");
        items=+1; //1 items total
        char sentig[]="I thank you kind one.  Here, I give you a LETTER.\n"
                      "\n\n"
                      "You can use it to enter the village.\n"
                      "\n\n"
                      "Well, good luck kind one, I wish you all the best...\n"
                      "\n\n"
                      "What will you do now?\n"
                      "\n\n"
                      "Press E to explore the surrounding area\n"
                      "\n\n"
                      "Press A to attack\n"
                      "\n\n"
                      "Press S to view your stats\n"
                      "\n\n";
                      size=strlen(sentig);
        for(x=0;x<size;x++)
        {   
            Sleep(40); 
            printf("%c",sentig[x]);
        }
        cout << "Choice?: " << endl;
        cin >> choice;
        }
        
        if (choice == 'a') 
        {
        noattack();
        }
        
        else if (choice == 's')
        {
        stats();
        }
        
    void noattack()
    {
    system("cls");
    cout << "There is nobody to attack\n" << endl;
    getch();
    }
    
    
    void stats()
    {
    cout << "\t\tSTATUS SCREEN\n";
    cout << "\n\n";
    cout << "Player Name " << pname;
    cout << "\n\n";
    cout << "Level is at " << level;
    cout << "\n\n";
    cout << "Experience " << exp;
    cout << "\n\n";
    cout << "Items totl " << items;
    cout << "\n\n";
    cout << "Magic levl " << magic;
    cout << "\n\n";
    cout << "Gold found " << gold;
    cout << "\n\n";
    cout << "Health is  " << phealth;
    cout << "\n\n";
    cout << "Press a key to exit" << endl;
      getch();
            }
    }
    
    return 0;
    } // end of function

  7. #7
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,801
    We are not the hand holders of programming association.
    I showed you exactly how to do it. Just put your function code how I showed you.
    While you are at it you should read the tutorial because its obvious you have not.
    Oh and also put some freaking indentation on your code. It is freaking ugly.
    Last edited by prog-bman; 06-02-2005 at 05:15 AM.
    Woop?

  8. #8
    ---
    Join Date
    May 2004
    Posts
    1,379
    as it comiles ok without errors
    I was stunned at that statement

  9. #9
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,794
    Minor nit:

    Code:
    Sleep(2000);
        system("cls");
        goto main;
        system("cls");
        }
    When are you ever going to execute that line if you always jump away before you get to it? Learn to use the looping features of the language instead of using goto.




    Code:
    int main()
    {
    
    void stats();
    void noattack();
    Try this instead:

    Code:
    void stats();
    void noattack();
    
    int main()
    {
    Don't try to prototype a function within a function. You're prototypes should be outside of any functions.

    The same goes for the actual functions themselves, put all the code for the functions outside of any other functions, you currently have them inside of your main function.

    Code:
    void stats()
    {
        cout << "\t\tSTATUS SCREEN\n";
        cout << "\n\n";
        cout << "Player Name " << pname;
        cout << "\n\n";
        cout << "Level is at " << level;
        cout << "\n\n";
        cout << "Experience " << exp;
        cout << "\n\n";
        cout << "Items totl " << items;
        cout << "\n\n";
        cout << "Magic levl " << magic;
        cout << "\n\n";
        cout << "Gold found " << gold;
        cout << "\n\n";
        cout << "Health is  " << phealth;
        cout << "\n\n";
        cout << "Press a key to exit" << endl;
        getch();
    }
    All the above variables are currently local to the main function. Within the scope of the function they are undefined. You will either have to make the variables global (bad), or pass them as arguments into the function (meaning the prototype, etc. for the function will need to change to indicate the arguments). Better yet would be to put all the variables into a "player" class/struct and then you would just need to pass a single object into the function instead of many.

    Learn to indent your code better. As it stands it is horrible. Use the handy "Preview Post" button to see what your post will look like before you submit it. Keep reworking your post till it looks readable and is formatted good then hit the "Submit" button.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  10. #10
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,475

    thanks guys

    i sorted it now, you were right, i did need to read up a little before i jumped in the deep end with that text prog.

    at least now i know how to do it, and i got rid of goto and used a while loop instead

  11. #11
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    >> why did i prototype them awhen above main.

    Simple I fixed the prototypes not knowing the funcs werent written so quickly added them after trying a build so as it would build successfully. I simply couldnt be bothered to remove them. lazy but what the hell!
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get RSSI value, send to sensor, sensor receive package, repackage it?
    By techissue2008 in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-04-2009, 09:13 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 12:49 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  4. how to get function call stack
    By George2 in forum C Programming
    Replies: 18
    Last Post: 11-11-2006, 06:51 AM
  5. Problem with Template Function and overloaded equality operator
    By silk.odyssey in forum C++ Programming
    Replies: 7
    Last Post: 06-08-2004, 04:30 AM

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