Hello! I am having trouble figuring out how to loop the program so that the user may enter more Fibonacci values instead of ending the program after the first series. Where am I going wrong?
#include <iostream>
usingnamespace std;
bool repeat()
{
int n;
int y;
int redo;
if(redo==y)
{
returntrue;
}
if(redo==n)
{
returnfalse;
}
}
int main()
{
int num3=0;
int num1=1;
int num2=2;
int fibnumber;
int redo;
cout<<"The 1st Fibonacci number is 1. ";
cout<<"\nThe 2nd Fibonacci number is 2. ";
cout <<"\nWhich other Fibonacci number would you like? ";
cin >> fibnumber;
while (fibnumber>=1)
{
cout << num1 ;
num3 = num1 + num2;
num1 = num2;
num2 = num3;
(fibnumber--);
cout <<" "<<endl;
}
cout<<"\nWould you like to know another? 'y' for yes, or 'n' for no."<<endl;
cin>>redo;
return 0;
}
helpvas.cpp: In function ‘int main()’:
helpvas.cpp:35:7: error: conflicting declaration ‘char redo’
char redo = 'y';
^
helpvas.cpp:26:6: error: ‘redo’ has a previous declaration as ‘int redo’
int redo;
^
helpvas.cpp:55:1: error: expected ‘}’ at end of input
}
^
No dice trying to add an outer loop, i also tried changing the if (redo = n) statement and taking out the n variable, but still no progress.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
bool repeat()
{
char redo = 'y';
while (redo == 'y')
int n;
int y;
if(redo==y)
{
returntrue;
}
else;
{
returnfalse;
}
}
you're welcome. You have to be careful of fib numbers. They get big very fast. That's why I changed from int to unsigned long long int. Even still, you need to set an upper limit. That is, if the user enters something greater than 60, ask the user to enter a value smaller than 60.