Alt · Lab Competency 1b Name: Objective: Create the solution and write a C++ pro
ID: 3725899 • Letter: A
Question
Alt · Lab Competency 1b Name: Objective: Create the solution and write a C++ program to solve the following problem. Verify and test your results. Problem: Display a series of numbers in sequence incrementing from a user selected number starting in the range of 100 to 189 and an ending range between 200 and 300 while incrementing by a user selected value in the range of 3 to 14. Prompt the user to input: 1. Input the starting value. 2. Input an ending value. 3. Input the increment value. 4. Ask the user if they want to run another sequence. Display the number sequence to the user. Use only for loops to create the number sequence. Ask the user if they want to run another sequence, then run the program if they request it. NOTES: Check inputs for valid numbers. If the input is out of range for the starting value, set it to 125 the input is out of range for the ending value, set it to 250. If the input is out of range for increment, set it to 8. DEMO your working code. Print out your program and staple it to the Lab Competency paper and hand it in.Explanation / Answer
#include <iostream>
using namespace std;
int main()
{
//initilize variable for starting, ending and incrementing values
int startValue, endValue, incValue;
char choice;
do
{
// taking starting value from user
cout << "Enter Starting value: ";
cin >> startValue;
//checking whether start value is in given range or not, if not assign 125
if (startValue < 100 || startValue > 189)
startValue = 125;
// taking ending value from user
cout << "Enter Ending value: ";
cin >> endValue;
//checking whether end value is in given range or not, if not assign 250
if (endValue < 200 || endValue > 300)
endValue = 250;
// taking increment value from user
cout << "Enter Incremental value: ";
cin >> incValue;
//checking whether increment value is in given range or not, if not assign 8
if (incValue < 3 || incValue > 14)
incValue = 8;
//printing sequence
cout << "The sequence is: " << endl;
for (startValue; startValue < endValue; startValue+=incValue)
{
cout << startValue << " ";
}
cout << endl;
//asking user to continue for other sequence
cout << "Do you want run another sequence(Y for continue, N for stop): ";
cin >> choice;
} while (choice != 'N');
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.