Hey guys,
In this article we are going to see how to get inputs from users and use it in the computer program using scanf function. Lets go ahead create something like this is you and this is your crush and you're going to have this many babies.
#include<stdio.h>
int main() {
char firstName[20];
char crush[20];
int numberOfBabies;
printf("What is your name? \n"); {we always have to give a prompt}
scanf("%s", firstName); {scanf is the function that allows user to input something} {we put firstName to specify where do you want to store this string?}
printf("Who are you going to marry? \n");
scanf("%s", crush{crush array});
printf("How many kids will you have? \n");
scanf("%d {for integer}", &numberOfBabies{for variable we always have to use ampersand but we don't have to use it for arrays});
printf("%s {first name} and %s {name of crush} are in love and will have %d babies", firstName, crush, numberOfBabies);
} {to verify everything in there is correct}
What is your name?
Thileban
Who are you going to marry?
Taylor
How many kids will you have?
53
Thileban and Tayler are in love and will have 53 babies
Comments
Post a Comment