//Develop a Fibonacci series and find the sum of all even numbers that is under 1,000,000.
int a = 1;
int b = 1;
int c = 0;
int sum = 0;
while (c < 1000000)
c = a + b;
a = b;
b = c;
std::cout << c << ", \n"; //Checking if the series is developing properly.
if (c < 1000000 && c % 2 == 0)
sum += c;
std::cout << "\n \n" << sum << "\n";
1) How do I adjust the sum to gather odd numbers instead? Any particular method(s) that can help with that?
2) What are some other methods or combination of methods to look into to develop a similar program?
I've just started C++ for little over a week as a hobby and am really not sure about the next vital method/technique to learn. Please point me in the right direction.
1) For odd numbers change if (c < 1000000 && c % 2 == 0) to if (c < 1000000 && c % 2 != 0)
2) Not sure, but maybe put this into a function?
As a next step find something you're interested in and write it. Maybe simulate the card-game war and find the probabilities of winning. Maybe take a look at the Euler project and work on some of those problems. Where do you want your programming to take you? Gaming? Math? GUIs? The internet?
Thanks for the suggestion, I'll try that. Haven't really gotten in functions yet.
Yea I'm trying out problems in Euler and have tried out several others elsewhere. I just keep going back to the same stuff I already know and not learning new stuff. Then again I'm a scrub and may be over thinking it.
Probably towards gaming. Are there any sites that provides those kind of exercises?
Code-chef is kind of fun. It provides some problems.
If you are interested in Gaming, what parts?
I suggest downloading an API such as SFML. This will give you a framework to start doing some really interesting things. With that you can make a mario side-scroller, Pac-Man, asteroids, or you may figure out how to start making an FPS. They have some good tutorials on that site which will get your imagination flowing.
Qt is also a nice framework which will let you create widgety applications or phone-style apps.
Frameworks are a nice place to start. If you really want to know how they work, you can then take them apart and see what's inside later.
Oh man that's a lot of stuff. Gonna keep me busy for a long while trying to figure it all out, thanks a bunch much appreciated! Gonna take a crack at SFML and stick around with Euler for the time being. Code-chef seems to be a little all over the place.
About parts of gaming, I'm not very sure. Probably due to the fact I've no idea how gaming programming is broken down. Do you mean like between animation programming and world programming or something like that?
Frameworks are a nice place to start.
Do you mean how to learn more about programming or it's a nice starting point to get into building apps?