Author Topic: inaccurate value of float variable printed out running on window 8  (Read 3244 times)

bevik

  • Guest
I have recently tried using code::blocks to brush up my skills on C, I am running it on window 8.
 
The compiler of choice during the project choice I have selected was the GNU GCC compiler

And this is the code I attempted to compile and run:
#include <stdio.h>
#include <stdlib.h>

int main()
{
    float f1;
    float f2 = 443.34;
    printf("f2:%f \n",f2);
    scanf("%f",&f1);
    f3 = f1 +f2;
    printf("f3: %f", f3);
    return 0;
}

my build log:

-------------- Build: Debug in LearnC3 (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall -g  -c C:\Users\soh\Desktop\CPlay\LearnC3\main.c -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\LearnC3.exe obj\Debug\main.o  
Output file is bin\Debug\LearnC3.exe with size 28.54 KB
Process terminated with status 0 (0 minute(s), 1 second(s))
0 error(s), 0 warning(s) (0 minute(s), 1 second(s))
 
and my output will be:
f2: 443.339996

which is not right the decimal value will not be of the same as long as I declared it to be of XX.YYY, unless I declared a whole number I will not receive the output of XX.000000 which puzzle me what is wrong with my setup.


another problem I faced is when I closed code::blocks and run it again, I cant compile my previous project. I tried to run code::blocks on admin mode but it doesn't solve the problem.

I will be issued with the following warning:
 ||=== Build: Debug in learnC2 (compiler: GNU GCC Compiler) ===|
ld.exe||cannot open output file bin\Debug\learnC2.exe Permission denied|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|
« Last Edit: May 17, 2014, 06:07:09 am by bevik »

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: inaccurate value of float variable printed out running on window 8
« Reply #1 on: May 17, 2014, 07:26:19 am »
Quote
ld.exe||cannot open output file bin\Debug\learnC2.exe Permission denied|

The above normally has two causes.
1. The program is still running
2. Your system security software is causing the problem. (Anti Virus is most often the security software causing problem)

For newbies the program is still running is the normal cause.

The other problem is in no way a CB problem but a programmers lack of knowledge issue on how Compilers/Computers do floating point.

Please read the rules and some of the CB FAQs before your next post.
Rules: http://forums.codeblocks.org/index.php/topic,9996.0.html
CB FAQs http://wiki.codeblocks.org/index.php?title=FAQ

CB User Docs: http://wiki.codeblocks.org/index.php?title=User_documentation

Tim S.

 
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org