Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C++ program to give a user the choice to select between 3 mathematical s

ID: 3624426 • Letter: W

Question

Write a C++ program to give a user the choice to select between 3 mathematical series:

a) Geometric (1/1 + 1/2 + 1/4 + 1/8......)

b) Harmonic (1/1 + 1/2 + 1/3 + 1/4......)

c) Alternating (1/1 - 1/2 + 1/3 - 1/4........)

Once the user selects the series, intake the positive limit from the user (between 10-10000) and use for loops to run the series and display the final result.

The program should continue in an uncontrolled loop and go back to the top after execution.

Here is an example of the Harmonic Series part of the program and the answer it should give:

int main ()
{
short num;
float ans=0;
cout << "Enter a number:";
cin >> num;
cout << "Num Ans" << endl;
while(num>0)
{
if(num%2==1)
ans=ans+1.0/num;
else
ans=ans-1.0/num;
num--;
cout << num << " " << ans << endl;

}
return 0;
}

AND HERE IS THE GEOMETRIC SERIES PART:

int main ()
{
float num=1,sum=0;
for(num=1;num<100;num++)
{
sum = sum + (1/num);
cout << "Num = " << num;
if(num<10) cout << " "; //used for output manipulation
cout << "1/Num = " << 1/num << "Sum = " << sum << endl;
}

I just need to figure out the Alternating series and a basic program to put it all together in a selectable menu. Tried using "switch/case", but had problems using "float" with it. "For" or "While" loops can be used as well as "if" statements of course.

PLEASE NEED HELP. I WANT TO GET THE BLACK SCREEN OF SUCCESS!!

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
int main()
{int choice,num,i;
float ans,n;
do
{
do
{
cout<<"What type of series do you want? ";
cout<<"1. Geometric ";
cout<<"2. Harmoonic ";
cout<<"3. Alternating ";
cin>>choice;
if(choice<1||choice>3)
      cout<<"Invalid choice ";
}while(choice<1||choice>3);
cout<<"Enter the limit 10-10000 ";
cin>>num;
while(num<10||num>10000)
    {
     if(num<10||num>10000)
        cout<<"Invalid entry ";
     cout<<"Enter the limit 10-10000 ";
     cin>>num;     
     }
   if(choice==1)
     {for(i=1;i<=num;i+=i)
       {ans = ans + (1./i);
       cout << "Num = " << i;
       if(i<10) cout << " "; //used for output manipulation
       cout << " 1/Num = " << 1./i << " Sum = " << ans << endl;
       }
     }  
   else if(choice==2)
       {for(i=1;i<=num;i++)
       {ans = ans + (1./i);
       cout << "Num = " << i;
       if(i<10) cout << " "; //used for output manipulation
       cout << " 1/Num = " << 1./i << " Sum = " << ans << endl;
       }
     }
    else
        {ans=0;
         for(i=1;i<=num;i++)
             {n=1./i;
              if(i%2==1)
                  ans+=n;
              else
                  ans-=n;
               cout << "Num = " << i;
               if(i<10) cout << " "; //used for output manipulation
               cout << " 1/Num = " << n << " Sum = " << ans << endl;
              }
          }
    }while(1);
return 0;
}           

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote