| | |
Im lost in my program, plesae please help
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2004
Posts: 2
Reputation:
Solved Threads: 0
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;
}
/* 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;
}
C Syntax (Toggle Plain Text)
int get_input (int *firstTerm, int *secondTerm, int *thirdTerm, int *fourthTerm, int *fifthTerm, int *sixthTerm); /* ... */ int main (void) { /* ... */ get_input (&fourthTerm, &fifthTerm, &sixthTerm);
C Syntax (Toggle Plain Text)
void get_input (int *firstTerm, int *secondTerm, int *thirdTerm) { /* ... */ } void get_input (int *fourthTerm, int *fifthTerm, int *sixthTerm) { /* ... */ }
C Syntax (Toggle Plain Text)
float avg_fee (float avg_fee); /* ... */ void avg_fee (int termFee, int termFee2, float *avg)
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...
C Syntax (Toggle Plain Text)
#include <stdio.h> #define UNIT_FEE 12 void get_input(int *a, int *b, int *c) { printf ("Please input the number of units (ex 10/12/10): "); scanf ("%d/%d/%d", a, b, c); } int add(int a, int b, int c) { return (a + b * c) * UNIT_FEE; } float average(int a, int b) { return (a + b) / 2.0F; } void print(float avg_fee) { printf ("The average fee is: $%.2f\n", avg_fee); } int main (void) { int first, second, third, total1, fourth, fifth, sixth, total2; float avg; get_input(&first, &second, &third); total1 = add(first, second, third); get_input(&fourth, &fifth, &sixth); total2 = add(fourth, fifth, sixth); avg = average(total1, total2); print(avg); return 0; } /* my output Please input the number of units (ex 10/12/10): 20/15/30 Please input the number of units (ex 10/12/10): 5/6/9 The average fee is: $3174.00 */
![]() |
Similar Threads
- We have lost most of the program associations. (Windows Software)
- Lost all file program associations (Windows NT / 2000 / XP)
- I lost all my program on start menu and word/excel docs (Windows NT / 2000 / XP)
- Need help writing a program (C++)
- Writing a program that uses a Character Queue (C++)
Other Threads in the C Forum
- Previous Thread: Format a Partition
- Next Thread: Using an Array to declare multiple bitmap handlers
Views: 2185 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






