+ 3
Please guys how can i Write a computer program c that will tell you how old your mother was when she gave birth to you
writing program
16 Réponses
+ 16
here it is:
import datetime
now = datetime.datetime.now()
year = now.year
your_age = input('Enter your age: ')
mom_age = input('Enter your moms age: ')
born_yr = int(year) - int(your_age)
mom_yr = int(mom_age) - int(your_age)
print("Your were born in: " + str(born_yr) + " and your mother was:" + str(mom_yr))
+ 14
Ipang Thanks for the C code
I appreciate you bro
+ 12
i havent worked on C before i will do it with python to give you idea am working on it now
+ 11
Ipang thats right,
he could also add more by getting the current year substract age and he will get the year he was born..
+ 11
which language i will do it in python
+ 6
super!
+ 5
Hint:
- Ask for mom's age now
- Ask for child's age now
- Subtract mom's age with child's age and you got it : )
+ 4
I see no one yet to give answer in C language, so here's my noob way for a try. I wonder where all the C gurus went to ...
* Inspired by Genes code *
#include <stdio.h>
#include <time.h>
int main()
{
int momsAge, childsAge;
// Ask for mom's age
printf("Enter mom's age: ");
scanf("%d", &momsAge);
printf("%d years\n", momsAge);
// Ask for child's age
printf("Enter child's age: ");
scanf("%d", &childsAge);
printf("%d years\n", childsAge);
// Subtract momsAge with childsAge
// and print the calculation result
int result = momsAge - childsAge;
printf("Mom's age when you were born: %d years\n", result);
// Get current year
time_t t = time(NULL);
struct tm* dt = localtime(&t);
int currentYear = dt->tm_year + 1900;
// Show mom's and yours birth year
printf("Mom was born in %d, you were born in %d\n", currentYear - momsAge, currentYear - childsAge);
return 0;
}
+ 3
thanks guys
+ 3
thanks
+ 3
Genes, thanks for code inspiration bro, Cheers! : )
+ 2
@Genes very good idea : )
+ 2
can i get a worked example
+ 2
just c language
+ 2
alright
0
Mehn I av learned a lot this little time I had