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

Welcome! 1. Factorial 2. Sum 3. Random Number Generator Enter your choice, or \'

ID: 3631250 • Letter: W

Question

Welcome!

1. Factorial
2. Sum
3. Random Number Generator
Enter your choice, or 'q' to quit: 1

Enter an integer: 4
4! = 24

1. Factorial
2. Sum
3. Random Number Generator
Enter your choice, or 'q' to quit: 2

Enter an integer: 5
Sum(0,5) = 15

1. Factorial
2. Sum
3. Random Number Generator
Enter your choice, or 'q' to quit: 3

Enter two integers (Ex. 2 13): 5 8
How many random numbers do you want?
7
How many numbers per line?
3
xxxx6xxxx8xxxx7
xxxx5xxxx6xxxx5
xxxx7

1. Factorial
2. Sum
3. Random Number Generator
Enter your choice, or 'q' to quit: r

Wrong input! Try again!

1. Factorial
2. Sum
3. Random Number Generator
Enter your choice, or 'q' to quit: q

Goodbye!

Press any key to continue

Explanation / Answer

please rate - thanks

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
char menu();
void factorial();
void sum();
void random();
int main()
{char choice;
srand(time(0));
for(; ;)
{choice=menu();
switch(choice)
   {case '1': factorial();
              break;
    case '2': sum();
              break;
    case '3': random();
              break;
    case 'q': cout<<"Goodbye! ";
              system("pause");
              return 0;
   }
}
}
char menu()
{char choice;
do
{
cout<<"1. Factorial ";
cout<<"2. Sum ";
cout<<"3. Random Number Generator ";
cout<<"Enter your choice, or 'q' to quit: 3 ";
cin>>choice;
if(choice>='1'&&choice<='3'||choice=='q'||choice=='Q')
      return choice;
cout<<"Wrong input! Try again! ";
}while(1);
}
void factorial()
{int i,n,nf=1;
cout<<"Enter an integer: ";
cin>>n;
for(i=2;i<=n;i++)
      nf*=i;
cout<<n<<"! = "<<nf<<endl<<endl;
}
void sum()
{int n,i,sum=0;
cout<<"Enter an integer: ";
cin>>n;
for(i=1;i<=n;i++)
   sum+=i;
cout<<"(0,"<<n<<") = "<<sum<<endl<<endl;
}
void random()
{int n, line=0,per,i,j,start,stop;
cout<<"Enter two integers (Ex. 2 13): ";
cin>>start>>stop;
cout<<"How many random numbers do you want? ";
cin>>n;
cout<<"How many numbers per line? ";
cin>>per;
for(i=0;i<n;i++)
   {cout<<setw(5)<<rand()%(stop-start+1)+start;
    line++;
    if(line==per)
        {cout<<endl;
        line=0;
        }
   }
cout<<endl<<endl;
}

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