Hey, i wrote this program for fibonacci's sequence, it works, but im having a problem completing a modification of it, i want to write 2 programs , i have done the first , i need help on the second.
First problem: Write a program that accepts user input for the number of months, and computes the number of pairs of rabbits at that month. Use a for loop and within the for loop output the running total. (( ACCOMPLISHED ))
Second Problem: First problem: Write a program that accepts user input for the number of pairs of rabbits, and computes the minimum number of months it woud take to have that many pairs. Use a for loop and within the for loop output the running total.
(( NEED HELP ))
The C++ code is here:
Code:
/*****************************************************************************************
**************************************ASSIGNMENT 2****************************************
******************************************************************************************
* *
* Student Name: Colin Raphael *
* Student Number: 100727139 *
* Description: This program uses fibonacci's sequence to determine the number*
* of pairs of rabbits by a given input of month. *
* *
******************************************************************************************
******************************************************************************************
*****************************************************************************************/
#include <iostream>
using namespace std;
void main(void)
{
int f1=1,f0=0,f,x,i; //Declaring used variables
cout << "Enter the number of months: "; //Prompts user for number of months
cin >> x; //Stores variable
for (i=1; i<=x; i++) //loop statement
{
f = f1 + f0;
cout <<"In month " << i << " there are " << f << " pair(s) of rabbits." << endl; // Outputting loop statment
break; //stop loop
}
for (i=2; i<= x; i++)
{
f = f1 + f0;
f0 = f1;
f1 = f;
cout <<"In month " << i << " there are " << f << " pair(s) of rabbits." << endl; // Outputting loop statement
}
cout <<"After " << x << " month(s) there are " << f << " pair(s) of rabbits."<<endl; // conclusion
}
>> I need somebody to modify it to satisfy problem 2 , please and thanks for your help