Code::Blocks Forums

User forums => Help => Topic started by: pikopiko on February 29, 2020, 10:12:55 pm

Title: Codeblocks shows the wrong result.
Post by: pikopiko 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.
Title: Re: Codeblocks shows the wrong result.
Post by: stahta01 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 (http://forums.codeblocks.org/index.php/topic,9996.0.html)

Tim S.
Title: Re: Codeblocks shows the wrong result.
Post by: BlueHazzard 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...