Thread: Help!!!

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    3

    Help!!!

    I need help wiht this code that i am writing arrays confuse me my last comptuer teacher was an idiot<TONN> please help.... the program is a game five charcters five mission we need to know a save program and arrays.... here is code



    #include <stdio.h>
    #include <stdlib.h>
    #include <process.h>
    #include <string.h>
    #include <math.h>
    #include <time.h>
    #include "vars.h"
    #include <iostream.h>
    #include <conio.h>


    void clearscreen()
    {
    int i;
    i=0;
    for (i=1;i<=15;++i)
    {
    printf("\n");
    }
    }
    void main()
    {
    namesel();
    charsel();
    begin();
    game();
    clearscreen();
    adv1();
    clearscreen();
    }


    void charsel()
    {
    /* Choose Character*/
    printf("Enter your character class, Barbarian, Archer, Mage, or Assassin\n");
    scanf("%s",&class1[3]);
    class1[3]=toupper(class1[3]);

    switch (class1[3])
    {
    case 'B':
    {
    printf ("Barbarian, your stats are: Armor 8, Hit Points 8, and Attack d12.\n");
    armor = 8;
    hp = 8;
    attack = 12;
    break;
    }
    case 'A':
    {
    printf ("Archer, your stats are: Armor 6, Hit Points 6, Attack d10(long range), and d8 (short sword).\n");
    armor = 6;
    hp = 6;
    attack = 10;
    break;
    }
    case 'M':
    {

    printf ("Mage, your stats are: Armor 4, Hit Points 4, and Attack d8.\n");
    armor = 4;
    hp = 4;
    attack = 8;
    break;
    }
    case 'S':
    {
    printf ("Assassin, your stats are: Armor 6 and Hit Points 6.\n");
    armor = 6;
    hp = 6;
    attack = 8;
    break;
    }
    default:
    {
    system("cls");
    printf("\n for Barbarian type B ");
    printf("\n for Archer type A ");
    printf("\n for Mage type M ");
    printf("\n for Assassin type S \n");
    charsel();
    break;
    }
    }
    _flushall();
    }

    void begin()
    {
    /* Begin Adventure */

    printf ("It is time to begin your adventure...\n");

    system("pause");
    system("clr");
    }

    void namesel()
    {
    printf("The air is cold around you. You wonder if anyone is still alive. You see that you father was taken under arrest by the king of Underwood. You go to see him. He tells you that you must be worthy to bail your father out of jail, that you must become a hero before you get your father back. 'Go now, but beware if you do not do what I tell you then your clan will surely die!' WELCOME TO DARKSHYOUR!\n");
    printf ("what is your name?\n");
    printf ("(must be less than 10 characters, and contain no spaces.)\n");
    scanf("%s", name);
    printf("\n %s of Darkshyour.\n",name );
    printf ("\nWell then, %s of Darkshyour, be on your way, but be warned of the monsters ahead!\n",name);
    }

    void game()
    {

    }

    void adv1()
    {
    printf("King Newfrown needs your help.\n");

    printf ("He says, 'I need you to retrive my Glorious Sceptre of Righteousness; bring it back and recieve a reward.' Do you accept?\n");
    printf ("(Enter y or n.)\n");

    scanf("%c",&answr);

    answr = toupper(answr);
    switch (answr)
    {
    case 'Y': break;
    printf("Fine then but be on your way beware of all the monsters a head");

    case 'N':
    {
    system("clr");
    printf ("Oh well. GUARDS! KILL THE TRAITOR! You had your chance. Bye bye.\n");
    exit(1);
    }

    default:
    {
    system("clr");
    printf ("That wasn't a yes, so I'm assuming it was a no. GUARDS, KILL THEM!\n");
    exit(1);
    }
    }

    system("clr");
    printf("You enter the room");
    }





    please email me or post anwser
    [email protected]

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    194
    What exactly about arrays confuses you?
    Here is a tutorial from this site. http://www.cprogramming.com/tutorial/lesson8.html

    Here is a refernce for FILE i/o
    http://www.cplusplus.com/ref/cstdio/feof.html

    Code:
      FILE * pFile = NULL;
      long n = 0;
      pFile = fopen ("myfile.txt","wt");  //write in text mode
      if (pFile==NULL)
     {
         printf("Error with myfile.txt");
      }
      else
      {
          fprintf(pFile, "%d %d %d",var1,var2,var3); //this will write 3 vars to the text file
      }
      fclose (pFile);
      }
      return 0;
    To read in the text file you would open the file for reading +text "rt", and use fscanf.

  3. #3
    Unregistered
    Guest
    here are my varsh.h #ifndef game1_H
    #define game1_H

    char class1[3]; // Used in Class Selection
    char name[10]; // Used in the Name selection and storage
    char answr;// used in yes or no questions.
    int armor,hp,attack;



    void charsel(); // Function prototype for Character select.
    void begin();
    void namesel();
    void game();
    void adv1();


    #endif
    please email me the anwser or post
    [email protected]

Popular pages Recent additions subscribe to a feed