OCCRA
Go to Post Pulling off an off season during a hurricane isn't easy. - Arefin Bari [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Events   CD-Media   CD-Spy   FRC-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 02-14-2007, 07:09 PM
brennerator brennerator is offline
Registered User
#1560
 
Join Date: Jan 2005
Location: Silicon Valley
Posts: 75
brennerator is an unknown quantity at this point
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?
  #2   Spotlight this post!  
Unread 02-14-2007, 08:28 PM
JBotAlan's Avatar
JBotAlan JBotAlan is offline
Forever chasing the 'bot around
AKA: Jacob Rau
FRC #2586
Team Role: Mentor
 
Join Date: Sep 2004
Rookie Year: 2004
Location: Holly, MI
Posts: 715
JBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond reputeJBotAlan has a reputation beyond repute
Send a message via AIM to JBotAlan Send a message via Yahoo to JBotAlan Send a message via Skype™ to JBotAlan
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?5
1
1
2
3
5
8
13
21
34
55
And those are the fibs
Good luck with this and post back if you need help,

JBot
__________________
This post brought to you by Jacob Rau.
Junior Electrical Engineer/Computer Engineer at Michigan Technological University
Former Programming/Electrical mentor for FRC3418 (Robo Riot)
Former Programming mentor for FRC2586 (Copper Robotics)
Alumni programmer of FRC68 (Truck Town Thunder)
I can help with programming problems. Let me know if you need help. (I don't bite )
  #3   Spotlight this post!  
Unread 02-14-2007, 09:45 PM
Kevin Watson's Avatar
Kevin Watson Kevin Watson is offline
La Caņada High School
FRC #2429
Team Role: Mentor
 
Join Date: Jan 2002
Rookie Year: 2001
Location: La Caņada, California
Posts: 1,331
Kevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond reputeKevin Watson has a reputation beyond repute
Re: RAndom C++ Problem

Quote:
Originally Posted by brennerator View Post
#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?
Help with what? It looks like a Fibonacci number generator.

-Kevin
__________________
Kevin Watson
Engineering consultant to
Space Exploration Technologies (SpaceX) and
Google Advanced Technologies and Projects
http://kevin.org
  #4   Spotlight this post!  
Unread 02-14-2007, 10:35 PM
brennerator brennerator is offline
Registered User
#1560
 
Join Date: Jan 2005
Location: Silicon Valley
Posts: 75
brennerator is an unknown quantity at this point
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
  #5   Spotlight this post!  
Unread 02-14-2007, 10:37 PM
Adam Richards's Avatar
Adam Richards Adam Richards is offline
I'm baaaaaaack.
FRC #1902 (Exploding Bacon)
Team Role: College Student
 
Join Date: Jan 2005
Rookie Year: 2005
Location: Orlando, FL
Posts: 1,062
Adam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond reputeAdam Richards has a reputation beyond repute
Send a message via AIM to Adam Richards Send a message via Skype™ to Adam Richards
Re: RAndom C++ Problem

Quote:
Originally Posted by brennerator View Post
How can you make the user enter in one of the numbers in the sequence and have hte prog spit it out
Just run a test before the number is outputted. If the number is < the inputted number, continue, if number == the inputted number, end with result, if number > inputted number, return error to user.
  #6   Spotlight this post!  
Unread 02-15-2007, 12:49 PM
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
Re: RAndom C++ Problem

Code:
int fib(int number)
{
if(number==0 || number ==1) return number;
else return fib(number-1)+fib(number-2);
}
yay.
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.
__________________
Team 701
  #7   Spotlight this post!  
Unread 02-15-2007, 12:55 PM
Salik Syed Salik Syed is offline
Registered User
FRC #0701 (RoboVikes)
Team Role: Alumni
 
Join Date: Jan 2003
Rookie Year: 2001
Location: Stanford CA.
Posts: 514
Salik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud ofSalik Syed has much to be proud of
Send a message via AIM to Salik Syed
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.
__________________
Team 701
  #8   Spotlight this post!  
Unread 02-15-2007, 01:14 PM
FIRST JerseyKid's Avatar
FIRST JerseyKid FIRST JerseyKid is offline
Alumni
AKA: Erik Cokeley
FRC #0025 (Team Mercury)
Team Role: Alumni
 
Join Date: Oct 2002
Rookie Year: 1996
Location: Hightstown New Jersey
Posts: 52
FIRST JerseyKid is on a distinguished road
Send a message via AIM to FIRST JerseyKid Send a message via Yahoo to FIRST JerseyKid
Re: RAndom C++ Problem

i think u need a ; after the while
__________________
Team 1089 alumni coach.
  #9   Spotlight this post!  
Unread 02-15-2007, 02:04 PM
Cheezmeister Cheezmeister is offline
Registered User
FRC #0871
 
Join Date: Jan 2007
Location: Long Island
Posts: 8
Cheezmeister is an unknown quantity at this point
Re: RAndom C++ Problem

Quote:
Originally Posted by FIRST JerseyKid View Post
i think u need a ; after the while
Yep, that's right.
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Random Stuff Brm789 Chit-Chat 11 11-20-2003 03:13 PM
Random Thought... Marygrace Chit-Chat 12 05-14-2003 02:50 PM
How random is random???? archiver 1999 0 06-23-2002 08:59 PM
Random Marc P. Chit-Chat 138 02-13-2002 02:11 PM
Random Question... Jessica Boucher Chit-Chat 26 07-02-2001 08:37 PM


All times are GMT -5. The time now is 02:51 AM.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi