C programming Use a dowhile loop to implement repeating unti

C++ programming:
Use a do...while loop to implement repeating until the user wants to quits.
Use a for loop to output the number of terms requested.
One line per input variable with the exact variable name followed by a description.
One line per output variable with the exact variable name followed by a description.
2. [12 points] The sequence 1, 1, 2. 3, 5. 8, 13, ...is called Fibonacci\'s sequence and it is defined recursively as ti1, t, tn-1t-2 for nENand n> 2. Let Fibonacci\'s sequence mod 10 be defined as in 1-1, m2 1, and mn (mn-l mn-2) % 10 for n E N and n > 2 Write a program that verifies the following facts about Fibonacci\'s sequence mod 10 for the number of terms requested by the user: . Every third term is even. Every fifth term is divisible by 5 Every fifteenth term is 0. CPSC 1620 Assignment 5 Assume that the program will prompt the user to enter the number of terms repeatedly until the user wants to quit. Sample output: This is the Fibonacci Sequence mod 10 fact checker. How many terms do you wish to check? 17 3: 2-even 5: 5divisible by 5 6: 8 even 9: 4 even 10: 5- divisible by 5 11: 9 12: 4 - evern 13: 3 14: 7 15: 0even- divisible by 5- is zero 16: 7 17: 7 Would you try again (Y/N) N

Solution

Tested on Ubuntu,Linux

/*****************Fibonacci.cpp******************/

# include <iostream>

using namespace std;

int main(){

//variable declaration
int N;//for Number of terms
int m1=1,m2=1,result=0,termsCount=0,modResult=0,flag=0;
char choice;

std::cout<<\"This is the Fibonacci Sequence   mod 10 fact Checker\"<<std::endl;

do{
   /*Prompt for input*/
std::cout<<\"How Many terms do you wish to check? \";
std::cin>>N;
/*If N>=2 then it will execute below code */
if(N>=2)
{
  

/*Resetting variable again to initial state*/
m1=1,m2=1,result=0,termsCount=0,modResult=0,flag=0;

/*Printing first Two terms*/
std::cout<<++termsCount<<\":\"<<m1<<std::endl;
std::cout<<++termsCount<<\":\"<<m2<<std::endl;
  
   while(N>2){
       /*Computing result mod 10*/
       termsCount+=1;//increasing term count
       result=(m1+m2)%10;//mod 10
       m1=m2;
       m2=result;
       //mod result 5
       modResult=result%5;
      
       /*If result mod 2 is zero*/
       if(result%2==0){
           flag=1;
           std::cout<<termsCount<<\": \"<<result<<\" - \"<<\"even\";
          
           if(modResult==0){
          
           std::cout<<\" - \"<<\"divisible by 5\";
          
           }
           if(result==0){
               std::cout<<\"- is Zero\"<<std::endl;
           }else{
             
               std::cout<<std::endl;
           }
         
       }
       /*If result mod 5 is zero and result is not 0*/
       if(modResult==0 && result!=0){
           flag=1;
           std::cout<<termsCount<<\": \"<<result<<\" - \"<<\"divisible by 5\"<<std::endl;
          
       }
       /*Result is zero and flag not equal to 1 means above condition was not execute*/
       if(result==0&& flag!=1){
           flag=1;
               std::cout<<\"- is Zero\"<<std::endl;
           }
           /*If all above condition was not execute*/
       if(flag==0){
           std::cout<<termsCount<<\": \"<<result<<std::endl;
          
       }
       /*Resetting flag to 0*/
       flag=0;
       /*decreasing to 1*/
           N--;
  
  
}
}
else{
   std::cout<<\"Please Enter Number of Terms >=2 \"<<std::endl;
}
std::cout<<\"Would you try again (Y|N)? \";
std::cin>>choice;

}while(choice==\'Y\' || choice == \'y\');

return 0;
}


/*****************output**************/

anshu@anshu:~/Desktop/chegg$ g++ Fibonacci.cpp
anshu@anshu:~/Desktop/chegg$ ./a.out
This is the Fibonacci Sequence   mod 10 fact Checker
How Many terms do you wish to check? 17
1:1
2:1
3: 2 - even
4: 3
5: 5 - divisible by 5
6: 8 - even
7: 3
8: 1
9: 4 - even
10: 5 - divisible by 5
11: 9
12: 4 - even
13: 3
14: 7
15: 0 - even - divisible by 5- is Zero
16: 7
17: 7
Would you try again (Y|N)? y
How Many terms do you wish to check? 10
1:1
2:1
3: 2 - even
4: 3
5: 5 - divisible by 5
6: 8 - even
7: 3
8: 1
9: 4 - even
10: 5 - divisible by 5
Would you try again (Y|N)? n

Thanks a lot

If You have any Query feel free to ask

C++ programming: Use a do...while loop to implement repeating until the user wants to quits. Use a for loop to output the number of terms requested. One line pe
C++ programming: Use a do...while loop to implement repeating until the user wants to quits. Use a for loop to output the number of terms requested. One line pe
C++ programming: Use a do...while loop to implement repeating until the user wants to quits. Use a for loop to output the number of terms requested. One line pe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site