Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have to write a program that i give a number of years and it to tell me how many months , days and hours are in that number of years. So i try this :

#include<stdio.h>
int main() {
	float years , months, days , hours;	
	scanf("%f", &years);
	months = 12*years;
	days = 365*years;
	hours = 24*days*years;
	printf(" %f years is  %f months " , months);
	printf(" %f years is %f days ", days);
	printf(" %f years is %f hours ", hours);
	return 0;
}


And i get the error : "
format '%f' expects a matching 'double' argument
"

What I have tried:

Pls help me i m new to coding and i m noob
Posted
Updated 30-Oct-22 5:03am
Comments
Mike Hankey 30-Oct-22 11:04am    
The error tells you the problem. Change float to double.
Rick York 30-Oct-22 11:56am    
Why are any of those variables floating point? None of your math involves fractional values or division so there is no reason they can't be integers.

1 solution

This is the same issue as your previous question at Pls help I m new to C and I can t figure it out[^], and you were given the solution. Try to make more effort to read the error message and look carefully at your code. You are using a format string that expects two parameter values, but you only pass a single value to the printf function.
C++
printf(" %f years is  %f months " , months);
         1             2              1   ... where is the years value?
 
Share this answer
 

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