Im lost in my program, plesae please help

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2004
Posts: 2
Reputation: FattMarrell is an unknown quantity at this point 
Solved Threads: 0
FattMarrell FattMarrell is offline Offline
Newbie Poster

Im lost in my program, plesae please help

 
1
  #1
May 18th, 2004
Okay so im making this program to accept three integers for two different users (# of units for three quarters, for two people). Then im multiplying that number by the unit cost of 12. Then finally i divide that by 2 to get the average for both people. This is my code and i messed up somewhere, ive been working on it for hours and im stuck!



/* This program uses three different functions to calculate the average
cost of a 3 quarter college school year for two people */
/* Written by: Matt Farrell */
/* Date: 05/8/04 */

#include <stdio.h>
#define UNIT_FEE 12

/*Prototype Declarations*/

int get_input (int *firstTerm, int *secondTerm, int *thirdTerm,
int *fourthTerm, int *fifthTerm, int *sixthTerm);

float avg_fee (float avg_fee);


int totalFee (int firstTerm, int secondTerm, int thirdTerm, int *totalFee);

int totalFee2 (int forthTerm, int fifthTerm, int sixthTerm, int *totalFee2);


int termFee (int units);

int TermFee2 (int units);



void print (float avg);

int main (void)
{
/*local definitions*/

int firstTerm, secondTerm, thirdTerm;
int fourthTerm, fifthTerm, sixthTerm;

int termFee, termFee2;
float totalFee, totalFee2;
float avg;



/*Statements*/
get_input (&fourthTerm, &fifthTerm, &sixthTerm);
get_input (&fourthTerm, &fifthTerm, &sixthTerm);
avg_fee (avg);
print (avg_fee);
return 0;
}



void get_input (int *firstTerm, int *secondTerm, int *thirdTerm)

{

printf ("Please input the number of units (ex 10/12/10): ");
scanf ("%d/%d/%d", firstTerm, secondTerm, thirdTerm);


return;
}


void get_input (int *fourthTerm, int *fifthTerm, int *sixthTerm)

{

printf ("Please input the number of units (ex 10/12/10): ");
scanf ("%d/%d/%d", fourthTerm, fifthTerm, sixthTerm);


return;
}


/*Calculate Fee*/
int totalFee (int firstTerm, int secondTerm, int thirdTerm, int *totalFee)

{
*totalFee = termFee (firstTerm) + termFee (secondTerm) + termFee (thirdTerm);

return fee;
}

int totalFee2 (int fourthTerm, int fifthTerm, int sixthTerm, int *totalFee2)
{

*totalFee2 = termFee (fourthTerm) + termFee (fifthTerm) + termFee (sixthTerm);

return fee;
}





/*Term Fee*/
void termFee (int totalFee, int totalFee2, int *termFee, int *termFee2)
{
/*statments*/
*termFee = (UNIT_FEE * totalFee);

*termFee2 = (UNIT_FEE * totalFee2);
return;
}


/*Average Fee*/
void avg_fee (int termFee, int termFee2, float *avg)
{
/*statements*/
*avg = (termFee + termFee2) / 2;
return avg_fee;
}


/*print*/
void print (float avg_fee)
{

/*statements*/
printf ("The average fee is: $%f\n", avg_fee);
return;
}
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Im lost in my program, plesae please help

 
1
  #2
May 18th, 2004
  1. int get_input (int *firstTerm, int *secondTerm, int *thirdTerm,
  2. int *fourthTerm, int *fifthTerm, int *sixthTerm);
  3. /* ... */
  4. int main (void)
  5. {
  6. /* ... */
  7. get_input (&fourthTerm, &fifthTerm, &sixthTerm);
If you were the compiler and the programmer told you to expect six arguments and the programmer only gave 3, would you be confused?


  1. void get_input (int *firstTerm, int *secondTerm, int *thirdTerm)
  2. {
  3. /* ... */
  4. }
  5. void get_input (int *fourthTerm, int *fifthTerm, int *sixthTerm)
  6. {
  7. /* ... */
  8. }
And then later the programmer defined the exact same function twice. Okay, compiler, which one does s/he mean?
  1. float avg_fee (float avg_fee);
  2. /* ... */
  3. void avg_fee (int termFee, int termFee2, float *avg)
Then told you to expect one thing and gave you another?

I don't know. I'd listen to the compiler, which ought to be providing plenty of feedback, 'cuz I'd stop there but I think a compiler has more patience at reading this code than the programmer.


[edit]
At risk of having completely done your assignment...
  1. #include <stdio.h>
  2. #define UNIT_FEE 12
  3. void get_input(int *a, int *b, int *c)
  4. {
  5. printf ("Please input the number of units (ex 10/12/10): ");
  6. scanf ("%d/%d/%d", a, b, c);
  7. }
  8. int add(int a, int b, int c)
  9. {
  10. return (a + b * c) * UNIT_FEE;
  11. }
  12. float average(int a, int b)
  13. {
  14. return (a + b) / 2.0F;
  15. }
  16. void print(float avg_fee)
  17. {
  18. printf ("The average fee is: $%.2f\n", avg_fee);
  19. }
  20. int main (void)
  21. {
  22. int first, second, third, total1, fourth, fifth, sixth, total2;
  23. float avg;
  24. get_input(&first, &second, &third);
  25. total1 = add(first, second, third);
  26. get_input(&fourth, &fifth, &sixth);
  27. total2 = add(fourth, fifth, sixth);
  28. avg = average(total1, total2);
  29. print(avg);
  30. return 0;
  31. }
  32. /* my output
  33. Please input the number of units (ex 10/12/10): 20/15/30
  34. Please input the number of units (ex 10/12/10): 5/6/9
  35. The average fee is: $3174.00
  36. */
[/edit]
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 254
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Im lost in my program, plesae please help

 
0
  #3
May 19th, 2004
:o Typo in add. Left as an exercise?
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 2
Reputation: FattMarrell is an unknown quantity at this point 
Solved Threads: 0
FattMarrell FattMarrell is offline Offline
Newbie Poster

Re: Im lost in my program, plesae please help

 
0
  #4
May 19th, 2004
wholy crap dave you own. I really love you :cheesy:

I looked it over a bit for the past hour and realised a few errors, but this really simplifies it. Thanks a bunch!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2185 | Replies: 3
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC