trying to make baby calculator!

+1 yashverdhan tiwari · November 5, 2014
hey bucky,
                     i am trying to make a baby calculator after watching your 10 tutorials of C. however i am not sucessfull, but  i                        think i am too close to it. can u please check it out whats the mistake?


#include <stdio.h>
#include <stdlib.h>

int main()
{

  char firstName[20];
  char lastName[20];
  int firstNameAge;
  int currentYear;
  int birthYear;
  currentYear = 2014;
  firstNameAge = currentYear - birthYear;
  char crushFirstName[20];
  char crushLastName[20];
  int crushFirstNameAge;
  int crushBirthYear;
  crushFirstNameAge = currentYear - crushBirthYear;
  int numberOfBabies;
  numberOfBabies = firstNameAge - crushFirstNameAge;
  printf("Your Name Buddy?\n");
  scanf("%s %s", firstName, lastName);

  printf("Your Birth Year?\n");
  scanf("%d", &birthYear);

  printf("who are you going to marry?\n");
  scanf("%s %s", crushFirstName, crushLastName);

  printf("what's her birth year?\n");
  scanf("%d", &crushBirthYear);

  printf("Congrats %s, You and %s will have %d babies", firstName, crushFirstName, numberOfBabies);


    return 0;
}



 

Post a Reply

Replies

Oldest  Newest  Rating
0 Nenad Nikolic · November 5, 2014
I rewrite it and it works like this:

#include <stdio.h>
#include <stdlib.h>

int main()
{

char firstName[20];
char lastName[20];
int firstNameAge,currentYear=2014,birthYear;

printf("Your First Name Buddy?\n");
scanf("%s", firstName);

printf("Your Last Name Buddy?\n");
scanf("%s", lastName);

printf("Your Birth Year?\n");
scanf("%d", &birthYear);

firstNameAge = currentYear - birthYear;

printf("Your current age is %d\n", firstNameAge);

char crushFirstName[20];
char crushLastName[20];
int crushFirstNameAge,crushBirthYear;

printf("Who are you going to marry?\n");

printf("Hes/Shes First name?\n");
scanf("%s", crushFirstName);

printf("Hes/Shes Last name?\n");
scanf("%s", crushLastName);

printf("What's her birth year?\n");
scanf("%d", &crushBirthYear);

crushFirstNameAge = currentYear - crushBirthYear;

printf("Hes/Shes current age is %d\n", crushFirstNameAge);

int numberOfBabies,howMuchBF1,howMuchBF2;

printf("How much babies would you like to have?\n");
scanf("%d", &howMuchBF1);

printf("How much babies would him/her like to have?\n");
scanf("%d", &howMuchBF2);

numberOfBabies = howMuchBF1 + howMuchBF2;

printf("Congrats %s, You and %s will have %d babies or more :) \n", firstName, crushFirstName, numberOfBabies);


return 0;
}


Your program might not work right because firstNameAge - crushNameAge can be "-" , and you need to declare birthyear before function not after , i mean at this part , you did it like this :

firstNameAge = currentYear - birthYear;

printf("Your Birth Year?\n");
scanf("%d", &birthYear);


So the program doesn't know what value birthYear takes , if you do it like this :

printf("Your Birth Year?\n");
scanf("%d", &birthYear);

firstNameAge = currentYear - birthYear;


It will know what values is birstYear and then it will works.

I hope i helped you out with this,i'm an newbie like you xD so if i didn't expressed right don't blame me ;p
  • 1

C

107,042 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator