View Single Post
Old 02-08-2005, 03:42 AM   #1 (permalink)
steve52
Upright
 
[C] problems with storing varilbes

I have a simple project for my intro to C class inwich we are suppose to pratice passing varibles through functions. It is a bit over modulized but that is the point of the exercies. The problem I am having is that when the user inputs two integers they are not being stored in the varibles. We have not gotten to pointers yet so I dont need to worry about that. I dont know what else to say so here is the code:

Code:
#include <stdio.h>
#include <math.h>

void getInput(int input1, int input2);
void calc(int input1, int input2, int sum, int iDiv, int iMod, float half1, float half2, float frac, double power);
void intOps(int input1, int input2, int sum, int iDiv, int iMod);
void floatOps(int input1, int input2, float half1, float half2, float frac);
double raiseToPower(int input1, int input2);
void display(int input1, int input2, int sum, int iDiv, int iMod, float half1, float half2, float frac, double power);

int main(void) 
{
    int input1;
    int input2;
    int sum, iDiv, iMod;
    float half1, half2, frac;
    double power;

   
   getInput(input1, input2);
   calc(input1, input2, sum, iDiv, iMod, half1, half2, frac, power);
   display(input1, input2, sum, iDiv, iMod, half1, half2, frac, power);
   
   
   system("pause");
   return 0;
   
}//end of main

/*******************************************************************************
Name: getInput()
Purpose: This function prompts the usr for two integers and stores them in memory
*******************************************************************************/
void getInput(int input1, int input2) 
{
   
   
   printf("%20s", "Sean Todd");
   
   printf("\nPlease enter two integers: ");
   
   scanf("%d%d", &input1, &input2);
   
   printf("%20d%20d", input1, input2);
   
   
}//end of getInput()

/*******************************************************************************
Name: calc()
Purpose: This function takes the data the usr entered and calculates the sum,
 the half of each number entered
*******************************************************************************/

void calc(int input1, int input2, int sum, int iDiv, int iMod, float half1, float half2, float frac, double power)
{
   printf("\n%20d %20d", input1, input2);

   intOps(input1, input2, sum, iDiv, iMod);
   floatOps(input1, input2, half1, half2, frac);
   power = raiseToPower(input1, input2);
   
}//end of calc()

/****************************************************************************
Name: intOps()
Purpose: perform all integer calculations
****************************************************************************/
void intOps(int input1, int input2, int sum, int iDiv, int iMod) 
{      

       sum = input1 + input2;
       iDiv = input1 / input2;
       iMod = input1 % input2;
       
}//end of intOps
   
/****************************************************************************
Name: floatOps()
Purpose: perform all integer calculations
****************************************************************************/
void floatOps(int input1, int input2, float half1, float half2, float frac) 
{
    half1 = (float) input1 / (2.0);
    half2 = (float) input2 / (2.0);
    frac = (float) input1 / (float) input2;
}//end of floatOps()
   
/****************************************************************************
Name: raiseToPower()
Purpose: perform all integer calculations
****************************************************************************/
double raiseToPower(input1, input2) 
{
   return pow(input1, input2);
   
}//end of raiseToPower()
   
/*******************************************************************************
Name: display()
Purpose: outputs the data to screen in report format
*******************************************************************************/
void display(int input1, int input2, int sum, int iDiv, int iMod, float half1, float half2, float frac, double power) 
{
    printf("\n%20s%20s", "Description", "Data");
    printf("\n%20s%20s", "-----------", "----");
    printf("\n%20s%20d", "Input1", input1);
    printf("\n%20s%20d", "Input2", input2);
    printf("\n%20s%20d", "Sum", sum);
    printf("\n%20s%20.1f", "Half of Input1", half1);
    printf("\n%20s%20.1f", "Half of Input2", half2);
    printf("\n%20s%20d", "Quotient", iDiv);
    printf("\n%20s%20d", "Remainder", iMod);
    printf("\n%20s%20.4f", "Fraction", frac);
    printf("\n%20s%20.0f", "Power", power);
    
    printf("\n\n");

}//end of display()
steve52 is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73