vendredi 29 janvier 2016

C: why does my nested if else statement not work

I am making a greedy algorithm to calculate number of coins in a value in cents stored in a variable. I had it all working out basically, but I had no way of differentiating between singular and plural for the denominations, ( printing "1 quarters" instead of "1 quarter" for example) and the way how I was doing it with sequential if conditions for each denomination, I couldn't do the same for singular or plural differentiation for each coin since it would give me back two quarters and one quarter instead of either or, so I'm trying to use an if else statement but it says that the else statement basically has no if statement to relate to which I don't understand. My compiler also says that the if statement nested in the other one has "no body" for some reason.

Don't mind the scanf, I will change to a better input method once I get the rest figured out.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main (void)
{
int n;
scanf("%d",&n);
int q = (n/25);
     if
(n > 24)
  {
      if (n > 49);
  {printf("%d quarters\n", q); }
  else
  {printf("one quarter\n");}
  }
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire