News:

As usual while waiting for the next release - don't forget to check the nightly builds in the forum.

Main Menu

Codeblocks shows the wrong result.

Started by pikopiko, February 29, 2020, 10:12:55 PM

Previous topic - Next topic

pikopiko

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.

stahta01

C Programmer working to learn more about C++.
On Windows 10 64 bit and Windows 11 64 bit.
--
When in doubt, read the CB WiKi FAQ. [url="http://wiki.codeblocks.org"]http://wiki.codeblocks.org[/url]

BlueHazzard

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...