Hello there, good day.
Is there a way for me to change when a user enter a year (eg: 1959), it will print out (age = 60)? Assuming that the current year is 2019.
1 2 3
printf("\nEnter your birth year : ");
scanf("%d", &birth_year);
printf("Age : ?? ");
Ps, given the condition that we can only use "stdio.h"
Seeing as there's no way for the program to be accurate to the month/day (most people born in 1959 are still 59 today), a simple 2019-birth_year would suffice. Perhaps add in a check to make sure it isn't negative.
Nick said "assuming the current year is 2019", so to me that means "just hardcode it".
But I'm curious, jonnin, what would your method be of determining the current year without #including <time.h> or <stdlib.h>? (Assuming that <stdio.h> doesn't implicitly include them).
Perhaps there's some sort of file-based solution, though that's probably OS-dependent.
I was thinking you could get the create timestamp off a file. I can't recall what C offers, but it seemed possible. Hopefully he does not need it, it would be an example of how not to do stuff ...
@jonnin , i dont it to be the current year, just hardcode it as 2019 is the current year. And yes, i can only include stdio and math.io as im still just starting up on coding c.
Thanks for the extra info tho. Appreciate it.
Actually one more thing (side question), why is it when i run the code on my laptop (2017 visual studio), it compiles and runs without any errors but when i try it on my college’s computer (2010 visual studio), it gives a lot of errors when i try running it also prompts something like “project out of date” when i try to run it there. Let me know if u need screenshots
Is it the same project/solution you're trying to run on on both 2017 and 2010 VS? They might not always be compatible. Copy the source text, not the project file/structure.