#include<stdio.h>
#include<stdlib.h>
//#include<cs50.h>
int main(void){
int minutes;
printf("minutes:");
int c=scanf("%d",&minutes);//if input here is character then second scanf doesn't ask value
printf("%d",c);
do{
if(!c){
int minl;
scanf("%d",&minl);//why scanf is not asking the value here
printf("retry");
break;
}
else{
printf("bottles: %d\n",minutes*12);
break;
}
}
while(1);
}
1 Answer
Wow! Your program has a poisoned logic, I think what you want is to imitate the cs50.h library, however given the pset in which you find yourself is not easy. Let us begin: scanf requires you to specify the type of data you'll typed in, according to your program is an integer
int c=scanf("%d",&minutes);
I think what you intend is that if c is a character the program asks the user to enter an integer. What happens if we type a character? . I do not know if it depends on the compiler but more likely is that character becomes zero, or the program undefined behavior that is probably what is happening