1

I'm stuck in water week 1 problem. My program works according to the check50 but I have it gives me 3 errors which I have no clue what they mean:

:( rejects "foo" minutes /expected prompt for input, not exit code of 0 :( rejects "" minutes /expected output, not a prompt for input :( rejects "123abc" minutes /expected prompt for input, not exit code of 0

Now I'm not too familiar with these errors, but it seems that the check50 tried in an input "foo", then "" and then "123abc" which resulted probably in my program giving them a 0 value. Now, I though in the instruction, there was no need for loops. Can someone help me out with this? I'm fairly new to programmation.

Here is my code:

#include <stdio.h>
int main(void)
{
     int bottle, minutes, num_bottles;

     printf("Minutes: \n");
     scanf("%d", &minutes);

     bottle = 12;
     num_bottles = bottle * minutes;
     printf("bottles: %d\n", num_bottles);
}

Answer to my own problem:

#include <stdio.h>
#include <cs50.h>

int main(void)
{
     int bottle = 12;
     int num_bottles;

     printf("minutes: \n");
     int minutes = GetInt();

    if (minutes > 0)
     {         
      num_bottles = bottle * minutes;
      printf("bottles: %d\n", num_bottles);
     }
    else
     {
      num_bottles = bottle * minutes;
      printf("retry: ")
     }
     return 0;
}
1
  • Found the problem on my own, figured that I forgot simply to put: if and else. Also, I removed scanf, since it seems its not the best for inputs. I added the cs50 library and replace the scanf for GetInt(). See my editing.
    – NewBie1234
    Commented Mar 18, 2016 at 6:29

3 Answers 3

2

Like I edited in my own problem and comment, I solved it.

 #include <stdio.h>
 #include <cs50.h>

 int main(void)
{
 int bottle = 12;
 int num_bottles;

 printf("minutes: \n");
 int minutes = GetInt();

if (minutes > 0)
 {         
  num_bottles = bottle * minutes;
  printf("bottles: %d\n", num_bottles);
 }
else
 {
  num_bottles = bottle * minutes;
  printf("retry: ")
 }
 return 0;
}
0
1

Not really a good solution. What happens if someone enters bad input twice? You need a solution that will keep prompting for valid input until it is entered. Time to discover what a while loop is.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

2
  • Thanks for the comment, its not a ''complete'' solution but the loop was not required in the week 1 problem, so I did not bothered with it. But yeah good thinking.
    – NewBie1234
    Commented Mar 18, 2016 at 17:49
  • Good point! It's been over a year since I did pset1 and it was updated for this year. I see now that the loop was not required, so yes, it's a whole solution. It's good to be kept on one's toes! ;-)
    – Cliff B
    Commented Mar 18, 2016 at 18:00
0

i have a trouble with "GetInt" it was written on my code, throws me an error(use of undeclared identifier 'GetInt') and of course i add a cs50.h, tried everything without result.

note* i update cs50 from terminal.

the solution that i found was, delete everything and start again and work perfect and past the check50.

i hope this help in the future to others :)

1
  • This should be put as a comment, not an answer to this problem.
    – NewBie1234
    Commented Sep 22, 2018 at 15:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .