T
Tybo93
Hello!
This program is meant to take two integers inputted by the user, and
calculate the sum, quotient, remainder, quotient in decimal form, half
of each integer, and an algebraic expression using the two integers.
I know it is probably over-modularized, but the program in itself is a
practice in transferring information through different functions.
My current problem is that the values for sum, quotient, remainder,
fraction, etc. are not saving and, therefore, are not being displayed
when the program prints the results (it comes out as all zeros... with
the exception of quotient and algebra... those come out as random
numbers). However, the program is saving the two integers, because
those are being printed to the screen.
Any and all help is greatly appreciated. My current code is as
follows. Thank you so much!
#include <stdio.h>
void getInput(int* pInput1, int* pInput2);
void calc(int input1, int input2);
void intOps(int input1, int input2, int* pSum, int* pQuotient, int*
pRemainder);
void doubleOps(int input1, int input2, double* pHalf1, double* pHalf2,
double* pFrac);
int algebra(int input1, int input2);
void display(int input1, int input, int sum, int quotient, int
remainder, double half1, double half2, double fraction, int
algebraic);
int main(void)
{
int input1, input2, sum, quotient, remainder, algebraic;
double fraction, half1, half2;
getInput(&input1, &input2);
calc(input1, input2);
display(input1, input2, sum, quotient, remainder, half1, half2,
fraction, algebraic);
return 0;
}
void getInput(int* pInput, int* pInput)
{
printf("\nPlease enter two integers: ");
scanf("%d%d", pInput1, pInput2);
}
void calc(int input1, int input2)
{
int sum, quotient, remainder, algebraic;
double half1, half2, fraction;
intOps(input1, input2, &sum, "ient, &remainder);
doubleOps(input1, input2, &half1, &half2, &fraction);
algebraic = algebra(input1, input2);
}
void intOps(int input1, int input2, int* pSum, int* pQuotient, int*
pRemainder)
{
*pSum = input1 + input2;
*pQuotient = input1 / input2;
*pRemainder = input1 % input2;
}
void doubleOps(int input1, int input2, double* pHalf1, double* pHalf2,
double* pFrac)
{
*pHalf1 = input1 * 0.5;
*pHalf2 = input2 * 0.5;
*pFrac = input1 / (double) input2;
}
int algebra(int input1, int input2)
{
int algebraic;
algebraic = 2 * input1 + 4 * input2 + input1 * input2 - input1 /
input2;
return algebraic;
}
void display(int input1, int input2, int sum, int quotient, int
remainder, double half1, double half2, double fraction, int algebraic)
{
//insert print statements here;
}
This program is meant to take two integers inputted by the user, and
calculate the sum, quotient, remainder, quotient in decimal form, half
of each integer, and an algebraic expression using the two integers.
I know it is probably over-modularized, but the program in itself is a
practice in transferring information through different functions.
My current problem is that the values for sum, quotient, remainder,
fraction, etc. are not saving and, therefore, are not being displayed
when the program prints the results (it comes out as all zeros... with
the exception of quotient and algebra... those come out as random
numbers). However, the program is saving the two integers, because
those are being printed to the screen.
Any and all help is greatly appreciated. My current code is as
follows. Thank you so much!
#include <stdio.h>
void getInput(int* pInput1, int* pInput2);
void calc(int input1, int input2);
void intOps(int input1, int input2, int* pSum, int* pQuotient, int*
pRemainder);
void doubleOps(int input1, int input2, double* pHalf1, double* pHalf2,
double* pFrac);
int algebra(int input1, int input2);
void display(int input1, int input, int sum, int quotient, int
remainder, double half1, double half2, double fraction, int
algebraic);
int main(void)
{
int input1, input2, sum, quotient, remainder, algebraic;
double fraction, half1, half2;
getInput(&input1, &input2);
calc(input1, input2);
display(input1, input2, sum, quotient, remainder, half1, half2,
fraction, algebraic);
return 0;
}
void getInput(int* pInput, int* pInput)
{
printf("\nPlease enter two integers: ");
scanf("%d%d", pInput1, pInput2);
}
void calc(int input1, int input2)
{
int sum, quotient, remainder, algebraic;
double half1, half2, fraction;
intOps(input1, input2, &sum, "ient, &remainder);
doubleOps(input1, input2, &half1, &half2, &fraction);
algebraic = algebra(input1, input2);
}
void intOps(int input1, int input2, int* pSum, int* pQuotient, int*
pRemainder)
{
*pSum = input1 + input2;
*pQuotient = input1 / input2;
*pRemainder = input1 % input2;
}
void doubleOps(int input1, int input2, double* pHalf1, double* pHalf2,
double* pFrac)
{
*pHalf1 = input1 * 0.5;
*pHalf2 = input2 * 0.5;
*pFrac = input1 / (double) input2;
}
int algebra(int input1, int input2)
{
int algebraic;
algebraic = 2 * input1 + 4 * input2 + input1 * input2 - input1 /
input2;
return algebraic;
}
void display(int input1, int input2, int sum, int quotient, int
remainder, double half1, double half2, double fraction, int algebraic)
{
//insert print statements here;
}