function to get input from a user

+1 Matthew Perry · February 6, 2016
This is my problem:

A function to get input from the user. This function takes one argument (a character string that is the prompt for the user when entering input), prints the prompt, reads a single integer from standard input, and returns the integer value that was entered.

Would I write the function:

int prompt (char a)
{
char a = "enter number of %s"
return;
}

int main (void)
{
char a = twenties;
prompt(a)
}


I am not really sure how to write a function that prompts a user to enter a certain amount of money  and then returns the value so that I can input it into some math functions. Any help would be appreciated.

Post a Reply

Replies

Oldest  Newest  Rating
0 Jonathan Chinen · February 17, 2016
https://www.youtube.com/watch?v=_oyuKw3vBf8&index=56&list=PL6gx4Cwl9DGAKIXv8Yr6nhGJ9Vlcjyymq

His earlier tut vids explain how to get user input; this particular tut vid is probably more what you're looking for.
0 Laura Lee · February 6, 2016
Why is prompt of type int, if you don't return anything relevant?
char a can only hold one byte, not an entire string.
You pass char a as an argument but then you redeclare char a inside the prompt function.
You declare char a in main and assign it to some unknown variable twenties.
You then pass a into prompt which is a bit redundant because you already declare and assigned it then you redeclare and reassign it in prompt.
If you intended on passing a pointer to a inside the prompt function then assign it inside the prompt function, well you're just passing a copy.
You are not printing anything to the user. 
You don't need to write a function for input and output, they already exist.
  • 1

C

107,269 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator