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

To practice using these commands, write a C++ program that does the following. T

ID: 3757164 • Letter: T

Question

To practice using these commands, write a C++ program that does the following. The program shall prompt the user for a starting base integer value. If the starting base value is less than one or greater than 20 then the program shall print an error message; otherwise, it shall print three lines of integer values in a table format as shown below where the first line of data contains the starting base value and its calculated squared value. The next two lines contain the next two increments of the starting base value and their calculated squared values. Note that the underscores within the data values below should be replaced with blank spaces using the setw() format specifier.

Explanation / Answer

Since you didn’t provide the sample output of your program, I can only answer this based on my assumptions. Here is the required code you asked for. I’m not sure that if you missed any important things to mention in the question or not. This code will prompt the user to enter a value between 1-20, validate the value, and then print the number and its square for each value starting from base value and ending at base+3. If you have any doubts or if you are looking for something else, just drop a comment. I’ll help. . If you are satisfied with the solution, please rate the answer. Thanks

#include<iostream>

#include<iomanip>

using namespace std;

int main(){

              int base;

              cout<<"Enter starting base value (1-20): ";

              //getting starting base value

              cin>>base;

              //validating base value

              if(base<1 || base>20){

                             //invalid

                             cout<<"ERROR! only values between 1-20 are allowed"<<endl;

              }else{

                             //looping from i=base to i=base+3

                             for(int i=base;i<base+3;i++){

                                           //displaying i and the square of i (with a field width of 10)

                                           cout<<i<<setw(10)<<(i*i)<<endl;

                             }

              }

              return 0;

             

}

/*OUTPUT*/

Enter starting base value (1-20): 14

14       196

15       225

16       256

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