<Hi, I am supposed to write a code for my project. There are 3 functions: getRandom, getSummation, and printFactor. The getRandom function has two parameters of integer type, min and max. It generates and returns a random number between min and max, with both inclusive. The 2nd function is called getSummation. The function has one parameter of integer type. It calculates and return the summation from 1 to num inclusive. This means that it will take the number generated by getRandom and will take it's factorial, but instead of multiplying, it will add. E.x. number generated: 4. getSummation: 1 + 2 + 3 + 4
The 3rd function is calle printFactors. The function has one parameter of integer type. It will print all of the factors of the random number generated by getRandom. The 4th and final function is the main function. It asks the user to enter the min and max, checks if the two numbers are valid.
The numbers are valid when both numbers are positive and min is not greater than max. If the numbers are not valid, then print a message. Otherwise, get a random number num between min and max using function getRandom. Then get the summation of num by calling function getSummation and print the summation, and finally Print all factors of num by calling function printFactors. Do not use goto statement, recursion, or global variables.
Here is my code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
void getRandom(int min, int max)
{
min = 2;
max = 36;
int number = rand() % 36 + 2;
return;
}
void getSummation(int sum)
{
int min;
int max;
int number = rand() % 36 + 2;
int Summation= 0;
for(int number = 1; number <= sum; number++)
{
Summation = sum;
Summation = 1 + (number*(number + 1));
}
return;
}
void printFactor(int num)
{
int number = rand() % 36 + 2;
num = number;
for(num = 1; number <= num/ 2; num++)
{
if(num % number == 0)
{
printf("The Factors are: %d %d \n", num, number);
}
}
return;
}
What I have tried:
I have tried changing the variables for getRandom, I have changed the rand() statement, I have changed the min max variables, I have tried changing the brackets around and I have tried a for loop and a while loop, I have tried rearranging the code around so that the int main code would go first, and I have also tried moving various bits of code from void to int main to see if maybe they would work there. Honestly, at this point, I have tried just about everything.