0

Getting started - first problems!

Hey everyone! My name is Max, I am from Germany and I am really getting into coding. It makes a lot of fun! So I just "released" my first little program, which is a tool to check if a number is prime or not. You can see it in my codes. Well it works really good, but I found a problem, which sucks a little bit. For low numbers it works really well, but if I give him maybe a 1000000000, the programm crashed and produces really weired output. Do you know what is the problem? I thought the problem is, that I have defined my input number as integer and I guess, with such a big number, the memory space of an integer is just full. How can I change it, that it will still run? Because changing int to float will produce an error. Thanks everyone and have a good rest of the day! Max

15th Jan 2019, 7:19 AM
Maximilian Spall
Maximilian Spall - avatar
2 odpowiedzi
+ 3
Yes, your ints overflow. You can choose a bigger number type like long long. Take a look here: https://de.cppreference.com/w/cpp/language/types
15th Jan 2019, 7:44 AM
HonFu
HonFu - avatar
+ 2
Thank you very much!
15th Jan 2019, 11:54 AM
Maximilian Spall
Maximilian Spall - avatar