Skip to main content
Formatted code for legibility.
Source Link
Luke Van In
  • 2.7k
  • 14
  • 26

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

void calc(int number, int change, int coins)
{
int result = change / number;
coins = coins + result;
change = change % number;
}
int main(void)
{

void calc(int number, int change, int coins)
{
    int result = change / number;
    coins = coins + result;
    change = change % number;
}

int main(void)
{      
    int change; 

    do
    {
        printf("How much I owe you: ");
        change = round(GetFloat() * 100);
    } 
    while (change < 0); 

    int coins = 0; 

    while (change > 0)
    {
        if (change >= 25)
        {
            calc(25, change, coins);    
        } 

        if (change >= 10)
        {
            calc(10, change, coins);  
        } 

        if (change >= 5)
        {
            calc(5, change, coins);
        } 

        if (change >= 1)  
        {
            calc(1, change, coins);
        }
    } 

    printf("Minimum number of coins needed is: %i \n", coins);
    return 0;
}

}

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

void calc(int number, int change, int coins)
{
int result = change / number;
coins = coins + result;
change = change % number;
}
int main(void)
{

int change;
do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} while (change < 0);
int coins = 0;
while (change > 0)
{
    if (change >= 25)
    {
        calc(25, change, coins);    
    }
    if (change >= 10)
    {
        calc(10, change, coins);  
    }
    if (change >= 5)
    {
        calc(5, change, coins);
    }
    if (change >= 1)  
    {
        calc(1, change, coins);
    }
}
printf("Minimum number of coins needed is: %i \n", coins);
return 0;

}

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

void calc(int number, int change, int coins)
{
    int result = change / number;
    coins = coins + result;
    change = change % number;
}

int main(void)
{      
    int change; 

    do
    {
        printf("How much I owe you: ");
        change = round(GetFloat() * 100);
    } 
    while (change < 0); 

    int coins = 0; 

    while (change > 0)
    {
        if (change >= 25)
        {
            calc(25, change, coins);    
        } 

        if (change >= 10)
        {
            calc(10, change, coins);  
        } 

        if (change >= 5)
        {
            calc(5, change, coins);
        } 

        if (change >= 1)  
        {
            calc(1, change, coins);
        }
    } 

    printf("Minimum number of coins needed is: %i \n", coins);
    return 0;
}
added 716 characters in body
Source Link

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

void calc(int number, int change, int coins)
{
int result = change / number;
coins = coins + result;
change = change % number;
}
int main(void)
{

int change;
 
do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} 
 while (change < 0);
int coins = 0;
while (change > 0)
{
    if (change >= 25)
    {
        calc(25, change, coins);    
    }
    if (change >= 10)
    {
        calc(10, change, coins);  
    }
    if (change >= 5)
    {
        calc(5, change, coins);
    }
    if (change >= 1)  
    {
        calc(1, change, coins);
    }
}
printf("Minimum number of coins needed is: %i \n", coins);
return 0;

}

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

int change;
 
do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} 
 while (change < 0);

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

void calc(int number, int change, int coins)
{
int result = change / number;
coins = coins + result;
change = change % number;
}
int main(void)
{

int change;
do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} while (change < 0);
int coins = 0;
while (change > 0)
{
    if (change >= 25)
    {
        calc(25, change, coins);    
    }
    if (change >= 10)
    {
        calc(10, change, coins);  
    }
    if (change >= 5)
    {
        calc(5, change, coins);
    }
    if (change >= 1)  
    {
        calc(1, change, coins);
    }
}
printf("Minimum number of coins needed is: %i \n", coins);
return 0;

}

that sad face is just too sad?
Source Link
Air
  • 2.1k
  • 18
  • 29

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-((

int change;

do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} 
while (change < 0);

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-((

int change;

do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} 
while (change < 0);

This is part of code from my greedy.c

The purpose of this do while loop is to get a valid input.

I'm having trouble, I tested it outside do while loop and it was working fine.

I think that mistake is really dumb but I really need help!!

I'm stuck here... :-(

int change;

do
{
    printf("How much I owe you: ");
    change = round(GetFloat() * 100);
} 
while (change < 0);
Formatted code for legibility, and to better conform to CS50 style guidelines. Formatted markdown to produce possibly intended output?
Source Link
Luke Van In
  • 2.7k
  • 14
  • 26
Loading
Source Link
Loading