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

Problem F1 Write a do while loop to require the user to enter two integers; the

ID: 3671144 • Letter: P

Question

Problem F1

Write a do while loop to require the user to enter two integers; the second integer must be equal to, or larger than, the first integer. Both integers must be at least 1 and not larger than 20. If they do not enter correct integers, give them error messages and make them do it again until they are correct.

After the acceptable integers have been entered, use a for loop to print a table of integers and their square roots for all integers from the first integer specified by the user to the last integer specified by the user, inclusive. Align the table and print 4 decimal positions

A sample table follows, for integers 7 to 9:

Test the program twice:
First test, first enter: first integer = 2, second integer = 0
and after that is rejected: first integer = 2, second integer = 4

Second test, first enter: first integer = 21, second integer = 5
and after that is rejected: first integer = 5, second integer = 5

(C++, CODEBLOCKS)

Explanation / Answer

//******intRecursion.cpp******//
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
bool pass=false;
int first,second,i;
double root;

do
{
    cout<<"Enter first integer(>=1)::";
    cin>>first;
    cout<<"Enter second integer(>=previous)::";
    cin>>second;
    if(first>=1&&first<=20&&second>=1&&first<=20&&first<=second)
    {
      for(i=first;i<=second;i++)
      {
        root = sqrt(i);
        printf("%d %0.4lf ", i, root);
      }
      pass = true;
    }else{
      cout<<" Please use the correct format for entering ";
      cout<<"Try Again!! ";
      continue;
    }

}while(!pass);

return 1;
}

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