![]() |
RAndom C++ Problem
#include <iostream>
using namespace std; int main() { int a,b,c,d; b=0; c=1; d=1; cout << "Which Fib do you want to find?"; cin >> a; do { cout << c << endl; c = c + d; cout << d << endl; d = c + d; b++; } while (b<a) cout << "And those are the fibs" << endl; } Any help? |
Re: RAndom C++ Problem
I'm not sure what this segment is supposed to do; a quick look at the source didn't reveal much (maybe I'm just being dense, but I didn't get it), but it won't even compile without a semicolon (;) at the end of the while.
Here's the output from the test run I gave it: Code:
Which Fib do you want to find?5JBot |
Re: RAndom C++ Problem
Quote:
-Kevin |
Re: RAndom C++ Problem
How can you make the user enter in one of the numbers in the sequence and have hte prog spit it out
|
Re: RAndom C++ Problem
Quote:
|
Re: RAndom C++ Problem
Code:
int fib(int number)User enters a term, it spits out the fib value for that term. Look at the inductive definition of Fibonacci series if you want to see why this works It runs in N*N time though.There are alot of clever optimizations that can be done to make this faster. |
Re: RAndom C++ Problem
Oops, i didn't even see the code you had so far... well I think what you are doing works fine, just follow the advice above.
|
Re: RAndom C++ Problem
i think u need a ; after the while
|
Re: RAndom C++ Problem
Quote:
|
| All times are GMT -5. The time now is 04:52. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi