1

hello guys i made my test version of code for greedy and i keep getting Errors expression result unused from my functions i saw pretty same problems guys asked here but answers didnt helped me i learning online (sorry for my english by the way) so i doesnt have anyone to ask for help. help me please

#include <stdio.h>
#include <cs50.h>
#include <math.h>

float change50 (float change_input);
float change25 (float change_input);
float change10 (float change_input);
float change5 (float change_input);
float change1 (float change_input);
float c50 = 0.50;
float c25 = 0.25;
float c10 = 0.10;
float c5 = 0.5;
float c1 = 0.1;
int main(void)
{
float change_input;
int coin_count = 0;
do
{
    printf("how much i owe you in float:\n");
    change_input = GetFloat();
}
while (change_input < 0);
do
{
    {
        printf("proceccing...%f\n", change_input);
        coin_count++;
    }
}
while (change_input > 0.49);
do
{
    change25;
    {
        printf("proceccing...%f\n", change_input);
        coin_count++;
    }
}
while (change_input > 0.24);
do
{
    change10;
    {
        printf("proceccing...%f\n", change_input);
        coin_count++;
    }
}
while (change_input > 0.09);
do
{
    change5;
    {
        printf("proceccing...%f\n",change_input);
        coin_count++;
    }
}
while (change_input > 0.04);
do
{
    change1;
    {
        printf("proceccing...%f\n", change_input);
        coin_count++;
    }
}
while (change_input > 0.00);
{
    printf("%f i owe you %i coins\n", change_input, coin_count);
}
}
float change50 (float change_input)
{
    return change_input -= c50;
}
float change25 (float change_input)
{
    return change_input -= c25;
}
float change10 (float change_input)
{
    return change_input -= c10;
}
float change5 (float change_input)
{
    return change_input -= c5;
}
float change1 (float change_input)
{
    return change_input -= c1;
}
1

The compile error messages are quite literal. The code is not doing anything with the values returned from the function calls. For example, look at the followinig:

do
{
    change25;
...

This code calls change25. The change25() function then returns a value. Where does that value get stored? You need something like this:

float x;
do
{
    x = change25;

As a side note, there are a lot of global variables in this code. Global vars should only be used when absolutely necessary and there's a good reason to do so. In this case, there is no need. Each of these vars could have been declared locally in the functions where they are used. You also could have used #define statements, since their values never change, such as #define c25 0.25

There are more problems coming, but you need the chance to work them out for yourself. ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • i cant use = because this is assigning and change25 is function so i cant make equation with it neither.... i ques i made more problems than answers with this functions
    – Andrew
    Oct 12 '16 at 22:40
  • Why do you think that? A function either returns a value or has a null return. If it has a null return, then you are correct. If a function returns a value, then that value can most definitely be assigned to a variable. All of your functions return a float.
    – Cliff B
    Oct 12 '16 at 22:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .