Hey guys first post here. I just switched my major to computer science last semester. So first my c++ class and this would be my second assignment. I need to write a function(in the from of a program for testing purposes) that prints the all the Fibonacci numbers less than 30,000. So my below code does all this except it prints one number after 30,000. Can anyone give me some idea on how to fix it? Or maybe a better a better way to implement it with a for loop? Thanks a ton in advance.
Code:#include<iostream> using namespace std; int main() { //Declaration unsigned int fib1=0, fib2=1, fib3=0; //fibonacci loop while(fib3<30000) { fib3=fib1+fib2; cout<<fib3<<endl; fib1=fib2; fib2=fib3; } return(0); }