Author Topic: Codeblocks shows the wrong result.  (Read 3413 times)

pikopiko

  • Guest
Codeblocks shows the wrong result.
« on: February 29, 2020, 10:12:55 pm »
Hi Guys,

i´m using codeblocks to practise my C-Skills. Today i noticed that i have an issue. If i try to implement my code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n= 1234;
    int anzahl=4;
    int ergebnis;

    for (int i=0 ; i<anzahl; i++){

        int a= pow(10.0 , 1+i);

        ergebnis= n % a;

        printf("%d\n\n",ergebnis);
    }

codeblock gives me the following result:

4

46

234

1234

The 46 ist wrong. Do anybody know why (The code is correct).

My version: 17.12

thanks in advance.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7582
    • My Best Post
Re: Codeblocks shows the wrong result.
« Reply #1 on: March 01, 2020, 12:43:01 am »
Code::Blocks is not a compiler!

Please read and follow the rules
http://forums.codeblocks.org/index.php/topic,9996.0.html

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

Offline BlueHazzard

  • Developer
  • Lives here!
  • *****
  • Posts: 3353
Re: Codeblocks shows the wrong result.
« Reply #2 on: March 01, 2020, 01:51:34 pm »
1) Try to make a rebuild and not only a run if you change code.
2) Use code tags when you post code
3) This is not the right forum for this kind of questions. Codeblocks is only a fancy text editor. If you get run time errors something in your code is wrong, or you did not compiler properly, but (al mostly) never codeblocks is the reason for your run time error
4) I would not mix floating point and integer arithmetic for something as simple as power of 10 (use multiply of integers instead) (floating point is dangerous ground for beginners)
5) on my machine your code runs fine
Now i am silent, because this is offtopic...