Alt · Lab Competency 1b Name: Objective: Create the solution and write a C++ pro
ID: 3725873 • 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
CODE:
#include <iostream>
using namespace std;
int main() {
int start,end,incr;
char ch;
do{
cout<<"Enter starting value =";
cin>>start;
if(start<100||start>189){
start=125;
}
cout<<"Enter ending value =";
cin>>end;
if(end<200||end>300){
start=250;
}
cout<<"Enter increment value =";
cin>>incr;
if(incr<3||incr>14){
start=8;
}
for(;start<end;start+=incr){
cout<<start<<" ";
}
cout<<"Do you want to run for another sequence[1 for yes /any other number for no]:";
cin>>ch;
}while(ch=='1');
}
OUTPUT:
Enter starting value = 100
Enter ending value = 200
Enter increment value =100 114 128 142 156 170 184 198
Do you want to run for another sequence[1 for yes /any other number for no]:2
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.