Click here to Skip to main content
15,504,830 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
You are a villager from a rural village. Your dream is to go to Rome and become an eques for the Imperial. However, on the road to Rome, you meet many fighters with various reasons to challenge you to a fight. You have to defeat all of them to arrive in Rome successfully. Assume every fighter (including you) has 4 integers for their status: HP, ATK, DEF, TYPE. When 2 fighters fight, they will both attack and take damage simultaneously. First, the damage will be calculated using the ATK of one fighter subtracted by the DEF of the other fighter to the minimum of 1. Second, depending on the TYPE of 2 fighters the dmg will change accordingly: • The Normal type (not Fibonacci and not Prime) is weak to only Prime or only Fibonacci type and takes 2x damage. • The Prime type is weak to the Fibonacci type and takes 2x damage. • The Fibonacci type is only weak to the type that is both Prime and Fibonacci and takes 2x damage (Fibonacci in this assignment start with 1, 1). • The number that is both Fibonacci and Prime is weak to normal type and takes 3x damage. Finally, the fighter who has HP<=0 first will lose. The winner will get half the loser’s ATK (round up) added to his ATK and the loser 2xDEF added to his HP and 1 added to his DEF After each round of the fight (1 round mean 2 fighter get to attack once), the program announced the atk of the round and the status of both fighters:

(In this example your TYPE is 2 which is both Fibonacci and Prime number vs fighter #1 TYPE 4 which is a normal number, so you take x3 damage. The #1 meaning he is the first fighter you fight on your road to Rome). If you win the system will announce:

If the fight is a draw the system will announce:

If you lose the system will announce:

If you defeat all the fighters on the road, the system will announce:

This exercise will receive these data from standard input (keyboard): Your status: HP, ATK, DEF, TYPE. The number of fighters you will meet on the road: nFighter. The status of each fighter you will meet on the road: eHP, eATK, eDEF, eTYP.

What I have tried:

#include <stdio.h>
#include <math.h>
struct villager{
int checkfibonacci(int n)
            int a = 0;
            int b = 1;
            if (n==a || n==b) return 1;
            int c = a+b;
                if(c == n) return 1;
                a = b;
                b = c;
                c = a + b;
            return 0;
int primenumber(int soA)
    if (soA < 2)    
        return 0;

    for (int i = 2; i <= sqrt((float)soA); i ++)
        if (soA%i==0)
            return 0;
    return 1;
 int checkTYPE(int n){
  if (primenumber(n)==0 && checkfibonacci(n)==0)  return 1;
  else if( primenumber(n)==1 && checkfibonacci(n)==0) return 2;
  else if (primenumber(n)==0 && checkfibonacci(n)==1) return 3;
  else if (primenumber(n)==1 && checkfibonacci(n)==1) return 4;

int main () {
  int n;
  scanf("%d", &n);
  printf("%d\n", primenumber(n));
  printf("%d\n", checkfibonacci(n));
  int numberofplayer = 0, TYPE = 0;
  do {
    scanf("%d", & numberofplayer);
    printf("the number of player : ");
  while (numberofplayer <=1 );
  int matrix[numberofplayer][4];
  printf("input the statistic of player \n");
  for (int i=0;i <numberofplayer;i++){
    for (int j;j<4;j++){
      scanf("%d", &matrix[i].[j]);
      if (matrix[i][j]<0){
        printf("input statistic of player again ");
Updated 26-Aug-22 4:20am
PIEBALDconsult 26-Aug-22 13:58pm    
Definitely do not check a number for prime or fibonacci that way each time. Cache the results.

1 solution

While we are more than willing to help those that are stuck, that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900