jeudi 9 mars 2017

Can't get the if statements/while loop to work

Can't get the if statements/while loop to work. If I use an int it will never allow me to enter choose another race. When I use a char the if statements don't work. I have absolutely no idea who to fix this. Any assistance that could be provided would be appreciated.

#include<stdio.h>
#include<string.h>
#include <stdlib.h>
#include <time.h>

struct player {   /*a struct to hold the player information.*/
int type[7];
int name[12];
int Smartness[7];
int Strength[7];
int MagicSkills[7];
int Luck[7];
int Dexterity[7];
int lifePoints[3];
}player;



int  main(void)
{
    struct player* ptr;
    srand(time(NULL));
    int numberPlayers,i,j,Smartness,Luck,Strength,Dexterity;
    int MagicSkills,name,slots,x,Hill,City,LevelGround,m,lifePoints;
    lifePoints = 100;
    char raceChosen[1];


    printf("Please enter the number of players you would like");
    scanf("%d",&numberPlayers);  /*take in the number of players*/

    struct player plyr[numberPlayers];
    i = 0;

    while( i<numberPlayers )
    {

    printf("Please enter the race you would like to play as \n"
    "Press elf for Elf \n"
    "Press 1 for Human \n"        /*taking in the race from the user*/
    "Press 2 for Ogre \n"
    "Press 3 for Wizard \n");
    scanf(" %c",&raceChosen);               


    if(raceChosen == "0"){
        printf("Please enter your name \n:");
        scanf("%d", &ptr->name[i]);
        Smartness = rand()%31 + 70;
        printf("%d\n",Smartness);
        scanf("%d", &ptr->Smartness[i]);
        Luck = rand()%41 + 60;
        printf("%d \n",Luck);
        scanf("%d", &ptr->Luck[i]);
        Strength = rand()%50 + 1;
        printf("%d \n",Strength);          /* generating the character */
        scanf("%d", &ptr->Strength[i]);
        Dexterity = rand()%100 + 1;
        printf("%d\n",Dexterity);
        scanf("%d", &ptr->Dexterity[i]);
        MagicSkills = rand()%31 + 50;
        printf("%d \n",MagicSkills);
        scanf("%d", &ptr->MagicSkills[i]);
        printf("\n********\n");

    }


    if(raceChosen == "1"){
        printf("Please enter your name \n:");
        scanf("%d", &ptr->name[i]);
        Smartness = rand()%31 + 70;
        printf("%d\n",Smartness);
        scanf("%d", &ptr->Smartness[i]);
        Luck = rand()%41 + 60;
        printf("%d \n",Luck);
        scanf("%d", &ptr->Luck[i]);
        Strength = rand()%50 + 1;
        printf("%d \n",Strength);
        scanf("%d", &ptr->Strength[i]);
        Dexterity = rand()%100 + 1;
        printf("%d\n",Dexterity);
        scanf("%d", &ptr->Dexterity[i]);
        MagicSkills = rand()%31 + 50;
        printf("%d \n",MagicSkills);
        scanf("%d", &ptr->MagicSkills[i]);
        printf("\n********\n");



    }

    if(raceChosen == "2"){
        printf("Please enter your name \n:");
        scanf("%d", &ptr->name[i]);
        Smartness = rand()%31 + 70;
        printf("%d\n",Smartness);
        scanf("%d", &ptr->Smartness[i]);
        Luck = rand()%41 + 60;
        printf("%d \n",Luck);
        scanf("%d", &ptr->Luck[i]);
        Strength = rand()%50 + 1;
        printf("%d \n",Strength);
        scanf("%d", &ptr->Strength[i]);
        Dexterity = rand()%100 + 1;
        printf("%d\n",Dexterity);
        scanf("%d", &ptr->Dexterity[i]);
        MagicSkills = rand()%31 + 50;
        printf("%d \n",MagicSkills);
        scanf("%d", &ptr->MagicSkills[i]);
        printf("\n********\n");




    }

    if(raceChosen == "3"){
        printf("Please enter your name \n:");
        scanf("%d", &ptr->name[i]);
        Smartness = rand()%31 + 70;
        printf("%d\n",Smartness);
        scanf("%d", &ptr->Smartness[i]);
        Luck = rand()%41 + 60;
        printf("%d \n",Luck);
        scanf("%d", &ptr->Luck[i]);
        Strength = rand()%50 + 1;
        printf("%d \n",Strength);
        scanf("%d", &ptr->Strength[i]);
        Dexterity = rand()%100 + 1;
        printf("%d\n",Dexterity);
        scanf("%d", &ptr->Dexterity[i]);
        MagicSkills = rand()%31 + 50;
        printf("%d \n",MagicSkills);
        scanf("%d", &ptr->MagicSkills[i]);
        printf("\n********\n");




    }
    i++;
    }

    }

Aucun commentaire:

Enregistrer un commentaire