Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Why is the results wrong?

+1 vote
asked Sep 24, 2021 by Nicolas Kuschnir (240 points)

When I run the program the numbers it gives me are totally wrong.

{
  int a, b;
  double molt, per1, per2;
  
  
  printf("enter salary per hour:  ");
  scanf("%d", &a);
  printf("enter hours worked per month:  ");
  scanf("%d", &b);
  molt = a * b;
  per1 = molt * 82 / 100;
  per2 = molt * 90 / 100;
 if(molt > 5000)
 {printf("salary per month is:%d ",&per1);}
 else {printf("salary per month is:%d ",&per2);}
 

}

1 Answer

0 votes
answered Sep 24, 2021 by Peter Minarik (86,180 points)
printf("salary per month is:%d ",&per1);

You are trying to print a double (long float), however, the format specifier is %d (decimal), not %lf (long float). Also, you are not actually printing the variable, but the address of the variable (& --> address-of operator).

Try this instead:

printf("salary per month is: %lf ",per1);
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...