0

Hi and thanks for taking the time to read this I appreciate it! I hope this is not the wrong place to put this but I am currently working on my code and have written different aspects but it keeps showing errors and I have searched across for answers but to no avail. The error code shows: error: passing 'double' to parameter of incompatible type 'const char*'

Please take a look at my code below for the problem set. I appreciate any feedback/changes! (I'm abysmally new so be nice :D)

  #include <cs50.h>
  #include <stdio.h>
  #include <math.h>
  double quarter, dime, nickel, penny;
  float change;
  int main (void)
{
 do 
{
change = get_float("Enter a change amount:");

} while(change <= 0);

for (quarter = 0.25; quarter < change; quarter++)
{
  for (dime = 0.10; dime < change; dime++)
  {
      for (nickel = 0.05; nickel < change; nickel++)
      {
          for (penny = 0.01; penny < change; penny++)
          {
          }
      }
  }
}
if (change >= quarter)
printf(change / quarter);
else if (change >= dime)
printf(change / dime);
else if (change >= nickel)
printf(change / nickel);
else if(change >= penny)
printf(change / penny);



}                

`

1 Answer 1

0

Without having run the code (having a password issue at the moment), this looks like the line having a problem:

printf(change / quarter);

printf takes a specification parameter as the first param, telling it what is being printed. That spec param will be in the form of a string with embedded placeholders for variables, specifying their type. The associated variables will follow. You simply can't printf a calculation as is being attempted here.

I suggest that you review the class material on printf and do a google search on printf to see how to use it correctly.

Tip: The code above creates vars before starting main. These are called GLOBAL VARIABLES. It is extremely bad practice to create global vars unless there's a really good reason to do so. (You'll run across this later.) When there are no functions in the code, and only main(), there is never a reason for a global. Create the vars inside of main.

Also, in the future, when looking for help with an error, please include and identify the specific line that has the error, so that it isn't necessary to compile and run the code.

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

You must log in to answer this question.

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