i wrote this code which gives error to the condition else if. i tried everything. if i remove this part the code works fine.
here is the code
Code:
#include <stdio.h>
#include <math.h>
#include <cs50.h>
int main(void)
{
float n;
do {
// prompt user for change
n = get_float("change owed: ");
}
while (n < 0);
int cents = round(n * 100);
// perform division
// computes quotient
int quotient = cents / 25;
// computes remainder
int remainder = cents % 25;
printf("Quotient = %d\n", quotient);
printf("Remainder = %d\n", remainder);
if (remainder >= 10) {
int quotient2 = remainder / 10;
int remainder2 = remainder % 10;
printf("Quotient2 = %d\n", quotient2);
printf("Remainder2 = %d\n", remainder2);
if (remainder2 >= 5) {
int quotient4 = remainder2 / 5;
int remainder4 = remainder2 % 5;
printf("Quotient4 = %d\n", quotient4);
printf("Remainder4 = %d\n", remainder4);
int addition, subtraction, multiplication, division, modulus;
addition = quotient + quotient4 + remainder4;
printf("number of coins: %d\n", addition);
} else {
int addition, subtraction, multiplication, division, modulus;
addition = quotient + quotient2 + remainder2;
printf("number of coins: %d\n", addition);
}
else
if (remainder < 10 && >=5) {
int quotient3 = remainder / 5;
int remainder3 = remainder % 5;
printf("Quotient3 = %d\n", quotient3);
printf("Remainder3 = %d\n", remainder3);
int addition, subtraction, multiplication, division, modulus;
addition = quotient + remainder;
printf("number of coins: %d\n", addition);
} else {
printf("%d\n", remainder);
}
}
}
thank you in advance for your input.
#