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

Problem: Given a range of values determine how many integers within that range,

ID: 3529698 • Letter: P

Question

Problem: Given a range of values determine how many integers within that range, including the end points, are multiples

of a third value entered by the user. The user should be permitted to enter as many of these third values as desired and

your output will be the sum of total multiples found. NOTE: THE USE OF USER-DEFINED FUNCTIONS IS

REQUIRED ON THIS ASSIGNMENT.

The user will always enter integer data. The final example demonstrates the input validation requirements.

? A -1 value will be entered to terminate the third input value entry

DO NOT use ARRAY!



Example Execution #1:

Enter the low range value: 5

Enter the high range value: 50

Enter a value to check within the range: 5

Enter a value to check within the range: 10

Enter a value to check within the range: -1

There are 15 total values that are divisible by the numbers in the range.

Example Execution #2:

Enter the low range value: 335

Enter the high range value: 475

Enter a value to check within the range: 17

Enter a value to check within the range: -1

There are 8 total values that are divisible by the numbers in the range



THis is what I have

#include<stdio.h>
#include<math.h>
// Function Declaration

int getlow();
int gethigh(int);
int getvalue(int, int);

int main (void)
{

int low = getlow();
int high = gethigh(low);
int final = getvalue(high, low);

printf(" There are %d total values that are divisible by the number in the range ", final);

return (0);
} //main

int getlow()
{
int low;
do
{
printf("Enter the low range value: ");
scanf("%d", &low);
if (low < 0)
{
printf("Error! Positive values only! ");
}
}while(low < 0);
return(low);
} // getlow

int gethigh(int low)

{
int high;
do
{
printf("Enter the high range value: ");
scanf("%d", &high);
if (low >= high)
{
printf("Error! the high range value must be greater than the low range value. ");
}
}while(low >= high);
return(high);
} // gethigh

int getvalue(int high, int low)
{
int value;
do
{
printf("Enter the value to check within the range: ");
scanf("%d", &value);

if (value == 0)
{
printf("Error! Positive value only! ");
}

if (value < -1)
{
printf("Error! Positive value only! ");
}


}while (value != -1);
return(value);
} //getvalue

I am getting stuck at the calculation part using "while loop". I wanted to use equation

range = high - low

result = (range / value) + 1

But the problem is I don't know how to pass all the variable "value" into this equation to calculate because there is not only one.

Please help I will rate.

Explanation / Answer

It looks like you don't need to pass your calculation function multiple values. Get one value, give that value (and your high and low) to your calculation function. When it returns the count, add that count to a sum somewhere, then repeat the whole thing. If you look at the first example execution, you can see that it is not a problem to double count numbers divisible by both. There are 10 numbers divisible by 5 from 1-50, and five numbers divisible by 10 from 1-50, and the answer is 15, even though all of the numbers divisible by 10 are also divisible by five. So you can just treat each value completely independently, and not worry about how many total values there are or how they relate to one another. The code already posted works, but I thought you might want to know why in case you want to do it a bit differently. Personally I would put that calculation in another function and have getValue call it instead of putting the code directly in getValue, especially since you emphasized that part of the assignment is to have multiple functions.

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