Hello every body
The doctor gave us to solve this assignment i tried to solve it but i could not can you tell me how i solve it please
the assignment is attached
and this is my code:
#include <iostream>
#include <iomanip> //FOR SETW
#include <climits>
using namespace std;
void Primes(int);
void Fibonacci(int);
void Menu(int& c);
void GetN(int& n);
bool IsPrime(int);
int i;
void main()
{//main
int choice, n;
do
{//do
Menu(choice);
switch(choice)
{//switch
case 1:
cout<<"primes:";
GetN(n);
Primes(n);
break;
case 2:
cout<<"fibonacci:";
GetN(n);
Fibonacci(n);
break;
case 3: break;
default: cout<<"Invalid menu option. Try again!\n\n";
}//switch
}//do
while (choice!=3);
}//main
void Menu(int& c)
{//MENU
cout<<"======================================"<<endl;
cout<<setw(15)<<"Print Series"<<endl;
cout<<"======================================"<<endl;
cout<<setw(3)<<"(1)"<<setw(3)<<"Primes Series"<<endl;
cout<<setw(3)<<"(2)"<<setw(3)<<"Fibonacci Series"<<endl;
cout<<setw(3)<<"(3)"<<setw(4)<<"Exit"<<endl;
cout<<"======================================"<<endl;
cout<<"Enter your selection (1,2,3): ";
cin>>c;
}//MENU
void GetN(int& n)
{//reads and returns a user entered word
cout<<"Enter the number of terms: ";
cin>>n;
while (n<=0)
{
cout<<"Enter the number of terms: ";
cin>>n;
}
}
void Primes (int n)
{//PRIMES
/* IsPrime(n);
while (IsPrime(n))
{//WHILE
if (IsPrime(n)==true)
{//IF
for (int row = 0; row < n/5 ; row++)
{//FOR
for (int col = 0; col < 5; col++)
{//FOR
cout << col;
}//FOR
cout << endl;
}//FOR
}//IF
IsPrime(n);
}//WHILE
*/
int pcount(0), count(0);
for( int i=0; count < n/5; count++)
{
while (IsPrime(i) && pcount < 5)
{
cout<<i<<" ";
i++;
pcount++;
}
cout<<endl;
}
}//PRIMES
bool IsPrime(int n)
{
for (int i=n-i ; i>1 ; i--)
{//FOR
if(n%i==0)
return false;
}//FOR
return true;
}
void Fibonacci(int n)
{
int num1 =-1;
int num2 =1;
int num3, row, col, count(0);
for (int row = 0; row < n/5 ; row++)
{//FOR
for (int col = 0; col < 5; col++)
{//FOR
num3 = num1+num2;
if (num3 < INT_MAX && num3 > INT_MIN)
{
cout<<setw(10)<<num3<<setw(24) ;
count ++;
num1 = num2;
num2 = num3;
}
else
break;
}//FOR
cout << endl;
}//FOR
cout<<"Fibonacci Series term exceeds C++ INT_MAX value after"<<count<<endl;
}