![]() |
| | #1 |
| Registered User Join Date: Nov 2002
Posts: 7
| error declaration terminated incorrectly help /* Name : Brian Brown */ /* Class : COSC 1415 */ /* Assignment : Asg 7 */ /* Date Due : Nov 25, 2002 */ #include <stdio.h> #include <math.h> void PrintHeading (void); void loan (void); float get_amount (void); float get_interest (void); int get_term (void); float calculate_payment (float a, float rm, int nm); void printInfo (float a, float rate, float rm, int ny, int nm, float mp); void print_amortize (float a, int nm, float rm, float mp); int main () { PrintHeading(); loan(); return 0; } void loan (void) { float a; float rate; int ny; int nm; float rm; float mp; a = get_amount(); rate = get_interest(); ny = get_term(); nm = ny * 12; rm = rate/nm; mp = calculate_payment (a, rm, nm); printInfo (a, rate, rm, ny, nm, mp); print_amortize (a, nm, rm, mp); } float get_amount (void) { float a; printf("Please enter amount of loan: "); scanf("%f", &a); return a; } float get_interest (void) { float rate; scanf("%f", &rate); printf("Please enter an interest rate: "); scanf("%f", &rate); return rate; } /*end get_amount */ int get_term (void) { int ny; scanf("%d", &ny); printf("Please enter term of the loan: "); scanf("%d", &ny); return ny; } float calculate (float a, float rm, int nm) { float p; float Q; float mp; p = pow((1 + rm), nm); Q = p/(p - 1); mp = a * rm *Q; return mp; } void printInfo (float a, float rate, float rm, int ny, int nm, float mp); { printf("The amount of the loan (principal): %6.2f", a); printf("\nInterest rate/year (percent): %4.1f", rate); printf("\nInterest rate/month (decimal): %5.6f", rm); printf("\nNumber of years: %6d", ny); printf("\nNumber of months: %6d", nm); printf("\nMonthly payment: %6.2f", mp); printf("\n Old Monthly Interest Principal New"); printf("\nMonth Balance Payment Paid Paid Balance"); } void print_amortize (float a, int nm, float rm, float mp) { int month; OldBalance = a; for(month = 1; month <= nm, month++) { InterestPaid = OldBalance * rm; PrincipalPaid = mp - rm; NewBalance = OldBalance - Principal; Printf("%5d %9.2f %9.2f %9.2f %9.2f\n"); OldBalance = NewBalance; } return 0; } void PrintHeading (void) { printf("Name : Brian Brown\n"); printf("Class : COSC 1415\n"); printf("Assignment : lab 7\n"); printf("Date Due : Nov 25,2002\n"); printf("\n"); } |
| belfour is offline | |
| | #2 |
| Registered User Join Date: Nov 2002
Posts: 7
| help could some one run this and tell me what i did wrong i really need to learn this |
| belfour is offline | |
| | #3 |
| Registered User Join Date: Apr 2002
Posts: 362
| I'm doing that now. First problem, I don't know C, though I'm faking it. ![]() Second problem, you've got numerous errors in your code that you should have caught on your own. Silly stuff, really. Third, I don't know C. (Did I mention that?) -Skipper
__________________ "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow |
| skipper is offline | |
| | #4 |
| Registered User Join Date: Nov 2002
Posts: 7
| well thx for the help i am new bie and this program has been giving me a headache for the last week i cant debug it i was told if i tried u guys would be glad to help me so i tried and now i am just totally lost |
| belfour is offline | |
| | #5 |
| Registered User Join Date: Apr 2002
Posts: 362
| This I, at least, got to compile and run: Code: /* Name : Brian Brown */
/* Class : COSC 1415 */
/* Assignment : Asg 7 */
/* Date Due : Nov 25, 2002 */
#include <stdio.h>
#include <math.h>
void PrintHeading (void);
void loan (void);
float get_amount (void);
float get_interest (void);
int get_term (void);
float calculate_payment (float a, float rm, int nm);
void printInfo (float a, float rate, float rm, int ny, int nm,
float mp);
void print_amortize (float a, int nm, float rm, float mp);
int main ()
{
char ch;
PrintHeading();
loan();
printf("Press any key to continue... ");
scanf("%ch", &ch);
return 0;
}
void loan (void)
{
float a;
float rate;
int ny;
int nm;
float rm;
float mp;
a = get_amount();
rate = get_interest();
ny = get_term();
nm = ny * 12;
rm = rate/nm;
mp = calculate_payment (a, rm, nm);
printInfo (a, rate, rm, ny, nm, mp);
print_amortize (a, nm, rm, mp);
}
float get_amount (void)
{
float a;
printf("Please enter amount of loan: ");
scanf("%f", &a);
return a;
}
float get_interest (void)
{
float rate;
//scanf("%f", &rate);
printf("Please enter an interest rate: ");
scanf("%f", &rate);
return rate;
} /*end get_amount */
int get_term (void)
{
int ny;
//scanf("%d", &ny);
printf("Please enter term of the loan: ");
scanf("%d", &ny);
return ny;
}
float calculate_payment (float a, float rm, int nm)
{
float p;
float Q;
float mp;
p = pow((1 + rm), nm);
Q = p/(p - 1);
mp = a * rm *Q;
return mp;
}
void printInfo (float a, float rate, float rm, int ny, int nm,
float mp)
{
printf("The amount of the loan (principal): %6.2f", a);
printf("\nInterest rate/year (percent): %4.1f", rate);
printf("\nInterest rate/month (decimal): %5.6f", rm);
printf("\nNumber of years: %6d", ny);
printf("\nNumber of months: %6d", nm);
printf("\nMonthly payment: %6.2f", mp);
printf("\n Old Monthly Interest Principal New");
printf("\nMonth Balance Payment Paid Paid Balance");
}
void print_amortize (float a, int nm, float rm, float mp)
{
int month;
float OldBalance = a;
for(month = 1; month <= nm; month++)
{
float InterestPaid = OldBalance * rm;
float PrincipalPaid = mp - rm;
float NewBalance = OldBalance - PrincipalPaid;
printf("%5d %9.2f %9.2f %9.2f %9.2f\n");
OldBalance = NewBalance;
}
return;
}
void PrintHeading (void)
{
printf("Name : Brian Brown\n");
printf("Class : COSC 1415\n");
printf("Assignment : lab 7\n");
printf("Date Due : Nov 25,2002\n");
printf("\n");
}
![]() Your prompts work fine. Up until the 'table' executes, you're okay, as well. (C programmers, feel free to jump in here, would ya?!?) Anyway, Belfour, let me digest this a little more. In the meantime, take what I've posted and start doing some debugging of your own. Pay attention to the 'scanf' stuff I've commented out because they hang the program. Also, your functions must re-declare your variables. They're out of scope! -Skipper
__________________ "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow |
| skipper is offline | |
| | #6 |
| Registered User Join Date: Nov 2002
Posts: 1,109
| Code: #include <stdio.h>
#include <math.h>
void PrintHeading (void);
void loan (void);
float get_amount (void);
float get_interest (void);
int get_term (void);
float calculate_payment (float a, float rm, int nm);
void printInfo (float a, float rate, float rm, int ny, int nm,
float mp);
void print_amortize (float a, int nm, float rm, float mp);
int main ()
{
PrintHeading();
loan();
return 0;
}
void loan (void)
{
float a;
float rate;
int ny;
int nm;
float rm;
float mp;
a = get_amount();
rate = get_interest();
ny = get_term();
nm = ny * 12;
rm = rate/nm;
mp = calculate_payment (a, rm, nm);
printInfo (a, rate, rm, ny, nm, mp);
print_amortize (a, nm, rm, mp);
}
float get_amount (void)
{
float a;
printf("Please enter amount of loan: ");
scanf("%f", &a);
return a;
}
float get_interest (void)
{
float rate;
scanf("%f", &rate);
printf("Please enter an interest rate: ");
scanf("%f", &rate);
return rate;
} /*end get_amount */
int get_term (void)
{
int ny;
scanf("%d", &ny);
printf("Please enter term of the loan: ");
scanf("%d", &ny);
return ny;
}
float calculate (float a, float rm, int nm)
{
float p;
float Q;
float mp;
p = pow((1 + rm), nm);
Q = p/(p - 1);
mp = a * rm *Q;
return mp;
}
void printInfo (float a, float rate, float rm, int ny, int nm, float mp)//notice lack of ;
{
printf("The amount of the loan (principal): %6.2f", a);
printf("\nInterest rate/year (percent): %4.1f", rate);
printf("\nInterest rate/month (decimal): %5.6f", rm);
printf("\nNumber of years: %6d", ny);
printf("\nNumber of months: %6d", nm);
printf("\nMonthly payment: %6.2f", mp);
printf("\n Old Monthly Interest Principal New");
printf("\nMonth Balance Payment Paid Paid Balance");
}
void print_amortize (float a, int nm, float rm, float mp)
{
int month;
OldBalance = a; //need to declare variable before use
for(month = 1; month <= nm; month++)//notice ; instead of , before month++
{
InterestPaid = OldBalance * rm; //need to declare variable before use
PrincipalPaid = mp - rm; //need to declare variable before use
NewBalance = OldBalance - Principal; //need to declare variable before use
Printf("%5d %9.2f %9.2f %9.2f %9.2f\n"); //needs to be printf, not Printf
OldBalance = NewBalance;
}
return 0; //funtion is void, no need for return statement
}
void PrintHeading (void)
{
printf("Name : Brian Brown\n");
printf("Class : COSC 1415\n");
printf("Assignment : lab 7\n");
printf("Date Due : Nov 25,2002\n");
printf("\n");
}
|
| alpha is offline | |
| | #7 |
| Registered User Join Date: Apr 2002
Posts: 362
| Belfour, Can we talk? Let's, also, think in terms of using descriptive variable names? 'a' for 'principal' doesn't get it! (I'm pulling your leg here, but not by much!) ![]() -Skipper
__________________ "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow |
| skipper is offline | |
| | #8 |
| Registered User Join Date: Apr 2002
Posts: 362
| I leave the formatting of the data, for display purposes, to you (you probably know better than I do...right?). I've played with it, but that's all I've done is "play". (A little success, but...) Your 'print_amortize' function is giving some God-awful value in the first column. Double-check both the type and value here. The fact that the value goes negative after 'x' number of iterations suggests that you're exceeding the limits of the 'type' that's being printed. (A "flag", as it were.) Again, I'm abyssmally weak in C so I can't say what's going on, or why. Hopefully, one of the other folks with a stronger background in C will offer some advice. ![]() -Skipper
__________________ "When the only tool you own is a hammer, every problem begins to resemble a nail." Abraham Maslow |
| skipper is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| No space left on device compilation terminated | lehe | Tech Board | 8 | 07-03-2009 11:20 AM |
| can someone help me with these errors please code included | geekrockergal | C Programming | 7 | 02-10-2009 02:20 PM |
| bcc 5.5 Declaration terminated incorrectly | P4R4N01D | Windows Programming | 9 | 05-28-2008 04:45 PM |
| Declaration terminated incorrectly | Griffin2020 | C Programming | 8 | 04-26-2002 11:53 PM |
| declaration terminated incorrectly | Clane | C++ Programming | 4 | 03-08-2002 12:09 AM |