2

I'm just starting out in learning to code in C using edX and I am sure this is a really simple mistake, which I can't spot.

I am getting an extra ./ which I can't work out where it is coming from.

This is what I get as the output

How many minutes does your shower last: 3
minutes: 3
bottles: 36./

I am using the CS50 IDE on Cloud 9 and my code is in the screenshot

Your help is appreciated.

Screenshot

This is my code:

 int main(void)
 {
int showerlength, bottle;

    printf("How many minutes does your shower last: ");
    scanf("%d", &showerlength);
    
    bottle = (showerlength * 12);
    
    printf("minutes: %d\n",showerlength );
    printf("bottles: %d\n",bottle );
    
}

This is the output I get

~/workspace/pset1/ $ ./water
How many minutes does your shower last: 3

minutes: 3
bottles: 36./
azh412
  • 28
  • 1
  • 5
suitandtie
  • 39
  • 8
  • 4
    Yeah, that doesn't really make sense. Maybe the web IDE you're using is printing something extra? – melpomene Dec 10 '16 at 22:00
  • I'm not getting this error using Clang. – Jack Deeth Dec 10 '16 at 22:01
  • 1
    Although *highly* unlikely, it could be the lack of a return. Try it with adding the line `return 0;` at the end of the function (after the last `printf` and before the closing brace). – deamentiaemundi Dec 10 '16 at 22:38
  • Try initializing `showerlength` to `0` before passing it to scanf. It might have some garbage in it that is causing this behavior. Other than that it might just be an artifact of the IDE you are using? – Brandon83 Dec 11 '16 at 00:53
  • Hi, did you check the returned flag of `scanf()` ? It should be equal to `1` if a good value has been entered for `showerlength`. In order to identify from where the extra `./` is coming, could you add some text between the `%d` and the `\n`, like `printf("bottles: %d \n",bottle );` ? – J. Piquard Jan 19 '17 at 21:46

2 Answers2

0

This does not look like an issue anymore.

I tested exactly the same code in CS50 IDE, and output is fine.

I even tested it with and without return(0) in the main function. It works fine.

Screenshot

Enis Arik
  • 665
  • 10
  • 24
0

This would not be a problem anymore. But, try the same thing in the new CS50 IDE, at ide.cs50.io.

azh412
  • 28
  • 1
  • 5