Skip to main content
added 152 characters in body
Source Link
MARS
  • 5.2k
  • 3
  • 14
  • 23

I don't understand why I keep getting an error message regarding the variable "amount." Can anyone identify/explain the problem and how to fix it? The relevant part of my code is below. Thanks in advance.

int main(void) { int coin_count = 0;

int main(void) 
{
    int coin_count = 0;
    
    do 
    {
        printf("How much change is owed (amount must be non-negative): \n"); 
        float amount = get_float(); 
    }
    while(amount < 0);
    
    int cent_amount = round(amount*100);
   
   while(cent_amount>0)
   {
       if(cent_amount > 25)
       {
           cent_amount = cent_amount - 25;
           coin_count++;
       }
       else if(cent_amount > 10)
       {
           cent_amount = cent_amount - 10;
           coin_count++;
       }
       else if(cent_amount > 5)
       {
           cent_amount = cent_amount - 5;
           coin_count++;
       }
       else if(cent_amount > 1)
       {
           cent_amount = cent_amount - 1;
           coin_count++;
       }
   }
   printf("Minimum number of coins used: %i\n", coin_count);
}

while(cent_amount>0) { if(cent_amount > 25) { cent_amount = cent_amount - 25; coin_count++; } else if(cent_amount > 10) { cent_amount = cent_amount - 10; coin_count++; } else if(cent_amount > 5) { cent_amount = cent_amount - 5; coin_count++; } else if(cent_amount > 1) { cent_amount = cent_amount - 1; coin_count++; } } printf("Minimum number of coins used: %i\n", coin_count); }

I don't understand why I keep getting an error message regarding the variable "amount." Can anyone identify/explain the problem and how to fix it? The relevant part of my code is below. Thanks in advance.

int main(void) { int coin_count = 0;

do 
{
    printf("How much change is owed (amount must be non-negative): \n"); 
    float amount = get_float(); 
}
while(amount < 0);

int cent_amount = round(amount*100);

while(cent_amount>0) { if(cent_amount > 25) { cent_amount = cent_amount - 25; coin_count++; } else if(cent_amount > 10) { cent_amount = cent_amount - 10; coin_count++; } else if(cent_amount > 5) { cent_amount = cent_amount - 5; coin_count++; } else if(cent_amount > 1) { cent_amount = cent_amount - 1; coin_count++; } } printf("Minimum number of coins used: %i\n", coin_count); }

I don't understand why I keep getting an error message regarding the variable "amount." Can anyone identify/explain the problem and how to fix it? The relevant part of my code is below. Thanks in advance.

int main(void) 
{
    int coin_count = 0;
    
    do 
    {
        printf("How much change is owed (amount must be non-negative): \n"); 
        float amount = get_float(); 
    }
    while(amount < 0);
    
    int cent_amount = round(amount*100);
   
   while(cent_amount>0)
   {
       if(cent_amount > 25)
       {
           cent_amount = cent_amount - 25;
           coin_count++;
       }
       else if(cent_amount > 10)
       {
           cent_amount = cent_amount - 10;
           coin_count++;
       }
       else if(cent_amount > 5)
       {
           cent_amount = cent_amount - 5;
           coin_count++;
       }
       else if(cent_amount > 1)
       {
           cent_amount = cent_amount - 1;
           coin_count++;
       }
   }
   printf("Minimum number of coins used: %i\n", coin_count);
}
Source Link

How to fix Error: unused variable (Pset 1 - Greedy)

I don't understand why I keep getting an error message regarding the variable "amount." Can anyone identify/explain the problem and how to fix it? The relevant part of my code is below. Thanks in advance.

int main(void) { int coin_count = 0;

do 
{
    printf("How much change is owed (amount must be non-negative): \n"); 
    float amount = get_float(); 
}
while(amount < 0);

int cent_amount = round(amount*100);

while(cent_amount>0) { if(cent_amount > 25) { cent_amount = cent_amount - 25; coin_count++; } else if(cent_amount > 10) { cent_amount = cent_amount - 10; coin_count++; } else if(cent_amount > 5) { cent_amount = cent_amount - 5; coin_count++; } else if(cent_amount > 1) { cent_amount = cent_amount - 1; coin_count++; } } printf("Minimum number of coins used: %i\n", coin_count); }