Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
So my code looks like this

#include <stdio.h>

void print_line(int index, int cents, int value)
{
printf("print_line(%d, %d, %d)\n", index, cents, value);
}
void coins(int cents)
{
    printf("coins(%d)\n", cents);
}
int main(void)
{
    int dollars, cents;
    printf("Pls enter total val");
    int n = scanf("%d.%d, &dollars, ¢s");
    if (n! = 2)
    {
        printf("Did not type correct\n");
    }
    else if (dollars < 0)
    {
        printf("dollars specified must be non neg\n");
    }
    else if (cents < 0 || cents > 99)
    {
        printf("The cents part spec mjust be 0...99");
    }
    else
    {
        coins(1+1);
    }
return 0;


    printf("main()\n");
}


I'm aware it has problems, I'm just trying to troubleshoot errors. For this line

int n = scanf("%d.%d, &dollars, ¢s");


the error comes up format ‘%d’ expects a matching ‘int *’ argument. And for this line

if (n! = 2)


The error is "error: expected ‘)’ before ‘!’ token"

How do I fix these

What I have tried:

I tried altering my code alr, but most of my alterations just cause more errors.
Posted
Updated 1-Oct-21 6:25am

1 solution

int n = scanf("%d.%d, &dollars, ¢s");
// the ¢s here has no meaning and the senond double quote is in the wrong place
I'm guessing you want something like,

int n = scanf("%d.%d", &dollars, &cents);


and
if (n! = 2)

should be
if (n != 2) // the '!' and '=' should be next to each other to be the inequality operator 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900