I am trying to complete the "Greedy" problem on CS50 and am running into some issues when attempting to compile my code so far.
Please see my code below:
#include <stdio.h>
#include <cs50.h>
#include <math.h>
int main(void)
{
// GET THE CORRECT INPUT FROM THE USER
float ChangeNeeded;
do
{
printf ("So, how much change do you need? \n");
ChangeNeeded = get_float();
}
while (ChangeNeeded < 0);
// CONVERT THE VALUE INTO CENTS
int RoundedChange = round(ChangeNeeded*100);
printf ("so you need %i cents\n", RoundedChange);
// DISTRIBUTE CHANGE AND COUNT COINS
int CoinCount = 0;
int Quarter = 25;
do
{
RoundedChange / Quarter;
++CoinCount;
}
while (RoundedChange >= Quarter);
printf ("The least amount of coins i can give is %i\n", CoinCount);
}
The error messages are as below:
~/workspace/workspace/pset1/ $ clang greedy.c
greedy.c:37:47: warning: expression result unused [-Wunused-value]
RoundedChange / Quarter;
~~~~~~~~~~~~~ ^ ~~~~~~~
1 warning generated.
/tmp/greedy-cf0462.o: In function `main':
greedy.c:(.text+0x2a): undefined reference to `get_float'
greedy.c:(.text+0x61): undefined reference to `round'
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
At first I thought there was an issue linking the "Math.h" librqry but I am not sure this is the case as when I also try to compile using the following command:
~/workspace/workspace/pset1/ $ clang greedy.c -lm
I get the following errors:
greedy.c:37:47: warning: expression result unused [-Wunused-value]
RoundedChange / Quarter;
~~~~~~~~~~~~~ ^ ~~~~~~~
1 warning generated.
/tmp/greedy-a1b3a8.o: In function `main':
greedy.c:(.text+0x2a): undefined reference to `get_float'
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
if Anyone could help me see my mistake I would be very grateful.
Thanks in advance.