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

The application has to follow structured programing methodology, with pointers c

ID: 3709984 • Letter: T

Question

The application has to follow structured programing methodology, with pointers carrying inter-functional communication.(C++)

1. Design an application that receives from the user two integer one "low" and another "high". If the user provides numbers in the correct order it proceeds with computing the total sum of all the integers from low to high (both the numbers included in computation). In the unlikely event the user provides the wrong order of numbers high number for "low" and low number for "high". It should provide to user an alert message and should correct this error

Explanation / Answer

The required code is written below. Note that there was no need of using pointers in this program, so I haven’t used any. Defined a method to find the sum of values between a range. In the main method, looped until user inputs a valid low-high pair and then sum of values between them are displayed. Thanks

//code.cpp

#include<iostream>

using namespace std;

//method to find the sum of values between low and high values

int sumOfIntegers(int low, int high){

                //initializing a variable to store the sum total

                int sum=0;

                //looping from low to high

                for(int i=low;i<=high;i++){

                                //adding to the total

                                sum+=i;

                }

                //returning the sum total

                return sum;

}

int main(){

                //variables for storing low and high values

                int low,high;

                //a variable to keep the track of user input

                bool validInput=false;

                //loops until valid low-high values are entered

                while(!validInput){

                                cout<<"Enter low value: ";

                                cin>>low;

                                cout<<"Enter high value: ";

                                cin>>high;

                                if(low>high){

                                                //invalid input

                                                cout<<"high value must be bigger than low"<<endl;

                                }else{

                                                //valid input, end of loop

                                                validInput=true;

                                }

                }

                //finding the sum total and displaying it

                int sum=sumOfIntegers(low,high);

                cout<<"Sum of values between "<<low<<" and "<<high<<" is "<<sum<<endl;

                return 0;

}

/*OUTPUT*/

Enter low value: 20

Enter high value: 1

high value must be bigger than low

Enter low value: 20

Enter high value: 60

Sum of values between 20 and 60 is 1640

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