#include
int main()
{
printf(\"how old are you? \");
int age = 0;
scanf(\"%d\", age);
printf(\"how much does your daily habit co
scanf("%d", daily);
needs to become
scanf("%d", &daily);
You need to pass the address of the variable (i.e., a pointer, this is done with the &
) to scanf
so that the value of the variable can be changed. The same applies for your other prompt. Change it to
scanf("%d", &age);
Now you should get this when you run your program:
% a.out
how old are you? 30
how much does your daily habit cost per day?
20
this year your habit will cost you: 7300.00
scanf works with references to variables
printf("how old are you? ");
int age = 0;
scanf("%d", &age);
printf("how much does your daily habit cost per day? \n");
int daily = 0;
scanf("%d", &daily);
double thisyear = daily * 365;
printf("\n");
printf("this year your habit will cost you: %.2f", thisyear);
The scanf function expects a pointer.
scanf("%d", &age);
Ditto for the line where you scanf on "daily".