As I was trying to structure the user input section of both problems, I ran into some errors that I don't understand. For Mario, I separated the user input of the problem and int main(void)
by placing int get_n(string prompt);
above 'int main(void)' and then creating a separate function that would be called into int main(void)
using the line of code int z = get_n("Height: ");
. The function I created to get user input is given below,
int get_n(string prompt)
{
int n;
do
{
n = get_int("%s", prompt);
}
while (n<1 || n>8);
return n;
}
This worked and I did not receive any errors! However, when I tried to do this same process within cash, I received the following error when using help50
,
"Looks like you're redeclaring the function get_float, but with a different return type on line 18 of cash.c. The function get_float is already declared in the library cs50.h. Try renaming your function."
Why am I receiving an error in this case and not in Mario? Isn't get_n also a part of the CS50 library? I changed my code to include the user question within int main(void)
and I did not receive any errors (code given below).
int main(void)
{
float dollars;
do
{
dollars = get_float("Change owed: ");
}
while (dollars<0);
return dollars;
Why does this work and the other case does not?
Thanks for your help!