1

After adding "aka C++17" flag on my codeblocks 17.12 IDE the code given below gives wrong output .

After facing this problem, when I removed "aka C++17" flag, output is correct, i again added the flag and the output is incorrect again.

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    double a,b,ans;
    scanf("%lf%lf",&a,&b);
    ans=a/b ;
    printf("%lf\n",ans);
    return 0;
}

I gave input 5 and 2 , the output is -0.000000 . What is changed in "aka C++17"?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
nsroni888
  • 11
  • 3
  • code::blocks comes with a rubbish compiler by default. I would recommend installing mingw-w64 , and in fact also recommend literally any IDE except code::blocks. – M.M Sep 09 '19 at 10:01
  • It would improve the question to show the exact input you gave. was it `5 and 2` ? Also you should check the return value of `scanf` and if it was not `2` then exit gracefully instead of carrying on to divide garbage values – M.M Sep 09 '19 at 10:02
  • 2
    Why are you using old C input and output functions when programming in C++? Why don't you use `std::cin` and `std::cout`? – Some programmer dude Sep 09 '19 at 10:02
  • As for ways to solve your current problem, first check what `scanf` [*returns*](https://en.cppreference.com/w/cpp/io/c/fscanf#Return_value) (as well as what `printf` [returns](https://en.cppreference.com/w/cpp/io/c/fprintf#Return_value)). Also step through the code statement by statement in a debugger to make sure it really does what you think it does. And as a final resort, check the generated assembly (for example [on the compiler explorer). – Some programmer dude Sep 09 '19 at 10:05
  • Does using `printf("%f\n", ans)` make a difference? – melpomene Sep 09 '19 at 10:45
  • Using "std::cin" or "std::cout" sometimes get time limit exceed on some contest problems. Thats why I use it as a time saver... Thanks for the recommendation. – nsroni888 Sep 09 '19 at 11:30
  • "aka C++17" looks like a wrong name. The acronym "aka" means "also known as"; given that, the real name of that option in the IDE contains more information. Please [edit] your post to mention that information. Or, if you don't find it, include a screenshot of that option. – anatolyg Sep 09 '19 at 14:35
  • To be honest, unless you're already have pretty good knowledge of C++ and algorithms, don't waste your time on online competition or judging sites. They don't really teach you anything but how to be good at such sites. The proposed example solutions are usually really bad code. [Get a few good books](https://stackoverflow.com/a/388282/440558), take classes, and learn the language and the basic algorithms properly instead. – Some programmer dude Sep 10 '19 at 06:53

0 Answers0