0

the goal is to add, delete, display dota heroes, and display specifics, and exit. thanks!! :)

#include<stdio.h>
#include<conio.h>
#include<string.h>

#define N 3

typedef struct{
 /*Place fields here.*/
}name;

typedef struct{
 /*Place fields here.*/
}hero;

typedef struct{
 /*Place fields here.*/
}hero_info;

typedef struct{
 /*Place fields here.*/
}hero_rec;

void displayMenu(void);
void initialize(hero_rec *s);
void addHero(/*Place fields here.*/);
void deleteHero(/*Place fields here.*/);
void displayHero(hero s);
void displayHeroes(/*Place fields here.*/);
void displaySpecific(/*Place fields here.*/);

void main(void)
{
 int choice;
 hero_rec s;

 clrscr();

 initialize(&s);
 do{
  displayMenu();

  printf("\n\n\tEnter your choice: ");
  scanf("%d", &choice);

  switch(choice)
  {
   case 1: addHero(&s); break;
   case 2: deleteHero(&s); break;
   case 3: displayHeroes(s); break;
   case 4: displaySpecific(s); break;
   case 5: exit(); break;

   default: printf("\n\tInvalid choice."); getch(); break;
  }
  getch();
 }while(choice != 5);

 getch();
}

void displayMenu(void)
{
clrscr();
printf("\n\t**********MY HEROES**********");
printf("\n\t1 ADD HERO");
printf("\n\t2 DELETE HERO");
printf("\n\t3 DISPLAY HEROES");
printf("\n\t4 DISPLAY SPECIFIC");
printf("\n\t5 EXIT");
printf("\n\t*******************************");
}

void initialize(hero_rec *s)
{
 int i;
 s->count = 0;      /*No heroes are inside the record yet*/
 for(i = 0; i < N; i++)
  s->heroes[i].h.avail = 0; /*Sets the availability of the hero to 0 meaning not available*/
}

void addHero(/*Place parameters here.*/)
{
 int i;
 if(/*Check if the record is full*/)
 {
  for(i = 0; i < N; i++)
  {
   if(/*Check if the hero's availability is 0 meaning the hero has been deleted*/)
   {
    /*Ask hero's information*/
    /*Set availability to 1 meaning the hero is part of the record*/
    /*Increment the number of heroes*/
    break;
   }
  }
 }
 else{
  printf("\n\tRecord is already full.");
 }
}

void deleteHero(/*Place parameters here.*/)
{
 int no, i;

/*If the number of heroes is not zero, ask for the hero number to be deleted*/
/*else display "No heroes are listed in the record"*/
/*Search for the hero number to be deleted*/ 
/*If the hero number has been found, set availability to 0, decrement the number of heroes and display that it has been successfully deleted.*/
/*else display hero not found*/
}

void displayHeroes(/*Place parameters here.*/)
{
 int i;
 if(/*Check if the number of heroes is not zero.*/)
 {
  for(i = 0; i < N; i++)
  {
    if(/*Check if the availability of the hero is 1*/)
    {
     displayHero(/*Pass hero's info*/);
    }
  }
 }else
    printf("\n\tNo heroes are listed.");
}

void displaySpecific(/*Place parameters here.*/)
{
 int choice, i, no, count;
 char str[30];
 if(/*Check if the number of heroes is not zero.*/)
 {
  printf("\n\t(1) Hero no\t\t(2) Hero type");

  printf("\n\tEnter choice: ");
  scanf("%d", &choice);

  switch(choice)
  {
   case 1: printf("\n\tEnter hero number: ");   scanf("%d", &no);
        /*Search for a particular hero's number*/
       if(/*hero's number is found and availability is 1*/)
        displayHero(/*Pass hero's info*/);
       else  /*Hero's id number is not found*/
        printf("\tHero not found.");
       break;
   case 2: printf("\n\tEnter hero type: "); scanf("%s", &str);
       for(i = count = 0; i < N; i++)
       {
        if(/*Compare hero's type with the given string and availability is 1*/)
        {
         displayHero(/*Pass hero's info*/);
         count++; /*Is incremented to monitor that there is an occurrence of that certain hero type*/
        }
       }
       if(count == 0)   /*Determines if that certain hero type did exist*/
        printf("\tHero not found.");

        break;

   default: printf("\n\tInvalid choice. ");
  }
 }else
    printf("\n\tNo heroes are listed.");
}

void displayHero(hero s)
{
 printf("\tHero no: %d\n", s.hero_num);
 printf("\tHero name: %s\n", s.hero_name.name);
 printf("\tAlias: %s\n", s.hero_name.alias);
 printf("\tHero type: %s\n", s.hero_type);
 printf("\tLife: %d\n", s.life);
 printf("\tMana: %d\n", s.mana);
}

Edited by Nick Evan: Fixed formatting

2
Contributors
1
Reply
3
Views
6 Years
Discussion Span
Last Post by gerard4143
-1

Could you please post code using the proper code tags and please format your code.

As for problems, the main function should return an integer and why are you using the getch() function when the standard provides fgetc().

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.