+ 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

19th Jul 2018, 6:22 AM
Emmanuel Ayo
Emmanuel Ayo - avatar
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))
19th Jul 2018, 7:47 AM
Genes Sambayena
Genes Sambayena - avatar
+ 14
Ipang Thanks for the C code I appreciate you bro
20th Jul 2018, 7:32 AM
Genes Sambayena
Genes Sambayena - avatar
+ 12
i havent worked on C before i will do it with python to give you idea am working on it now
19th Jul 2018, 7:01 AM
Genes Sambayena
Genes Sambayena - avatar
+ 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..
19th Jul 2018, 6:38 AM
Genes Sambayena
Genes Sambayena - avatar
+ 11
which language i will do it in python
19th Jul 2018, 6:58 AM
Genes Sambayena
Genes Sambayena - avatar
+ 6
super!
12th Sep 2018, 5:41 PM
Dmitriy Yakovlev
Dmitriy Yakovlev - avatar
+ 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 : )
19th Jul 2018, 6:36 AM
Ipang
+ 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; }
19th Jul 2018, 4:37 PM
Ipang
+ 3
thanks guys
19th Jul 2018, 6:57 AM
Emmanuel Ayo
Emmanuel Ayo - avatar
+ 3
thanks
19th Jul 2018, 8:44 PM
Emmanuel Ayo
Emmanuel Ayo - avatar
+ 3
Genes, thanks for code inspiration bro, Cheers! : )
20th Jul 2018, 7:59 AM
Ipang
+ 2
@Genes very good idea : )
19th Jul 2018, 6:40 AM
Ipang
+ 2
can i get a worked example
19th Jul 2018, 6:58 AM
Emmanuel Ayo
Emmanuel Ayo - avatar
+ 2
just c language
19th Jul 2018, 6:59 AM
Emmanuel Ayo
Emmanuel Ayo - avatar
+ 2
alright
19th Jul 2018, 7:02 AM
Emmanuel Ayo
Emmanuel Ayo - avatar
0
Mehn I av learned a lot this little time I had
22nd Jul 2021, 12:54 PM
Valoh Semi Bayne
Valoh Semi Bayne - avatar