can someone help me to check any problems in this program...i cant run my program..
/* calculate depreciation using one of three different methods */
#include <stdlib.h>
#include <stdio.h>
#include<ctype. h>
void SL (void);
void DDB (void);
void SYD (void);
main()
{
int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
while(toupper(a nswer1) != 'N')
{
system("CLS");
if(toupper(answ er2) != 'N')
{
printf("\nOrigi nal value: ");
scanf("%f", &value);
printf("Number of years: ");
scanf("%d", &N);
}
printf("\nMetho d: (1-SL 2-DDB 3-SYD) ");
scanf("%d", &choice);
val = value;
n = N;
switch(choice)
{
case 1:SL();break;
case 2:DDB();break;
case 3:SYD();break;
default:puts("i nvalid entry");
}
printf("\n\nAno ther calculation? [Y/N] ");
scanf("%1s", &answer1);
if(toupper(answ er1) != 'N')
{
printf("Enter a new set of data? [Y/N] ");
scanf("%1s", &answer2);
}
}
system("pause") ;
}
void SL (void)
{ int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
printf("\nStrai ght Line Method\n\n");
deprec = val/n;
for (year = 1; year <= n; year++)
{
val -= deprec;
printf("\nEnd of year %2d ", year);
printf("\nDepre ciation: %7.2f ", deprec);
printf("\nCurre nt value:%8.2f\n", val);
}
}
void DDB(void)
{
int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
printf("\nDoubl e Declining Balance Method\n\n");
for (year = 1; year <= n; year++)
{
deprec = 2*val/n;
val = deprec;
printf("End of year %2d ", year);
printf("Depreci ation: %7.2f ", deprec);
printf("Current value:%8.2f\n", val);
}
}
void SYD(void)
{ int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
printf("\nSum-of-the-Years\'-Digits method\n\n");
tag = val;
for (year = 1; year <= n; year++)
{
deprec = (n-year+1)*tag/(n*(n+1)/2);
val -= deprec;
printf("End of year %2d ", year);
printf("Depreci ation: %7.2f ", deprec);
printf("Current value:%8.2f\n", val);
}
}
thank you...
/* calculate depreciation using one of three different methods */
#include <stdlib.h>
#include <stdio.h>
#include<ctype. h>
void SL (void);
void DDB (void);
void SYD (void);
main()
{
int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
while(toupper(a nswer1) != 'N')
{
system("CLS");
if(toupper(answ er2) != 'N')
{
printf("\nOrigi nal value: ");
scanf("%f", &value);
printf("Number of years: ");
scanf("%d", &N);
}
printf("\nMetho d: (1-SL 2-DDB 3-SYD) ");
scanf("%d", &choice);
val = value;
n = N;
switch(choice)
{
case 1:SL();break;
case 2:DDB();break;
case 3:SYD();break;
default:puts("i nvalid entry");
}
printf("\n\nAno ther calculation? [Y/N] ");
scanf("%1s", &answer1);
if(toupper(answ er1) != 'N')
{
printf("Enter a new set of data? [Y/N] ");
scanf("%1s", &answer2);
}
}
system("pause") ;
}
void SL (void)
{ int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
printf("\nStrai ght Line Method\n\n");
deprec = val/n;
for (year = 1; year <= n; year++)
{
val -= deprec;
printf("\nEnd of year %2d ", year);
printf("\nDepre ciation: %7.2f ", deprec);
printf("\nCurre nt value:%8.2f\n", val);
}
}
void DDB(void)
{
int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
printf("\nDoubl e Declining Balance Method\n\n");
for (year = 1; year <= n; year++)
{
deprec = 2*val/n;
val = deprec;
printf("End of year %2d ", year);
printf("Depreci ation: %7.2f ", deprec);
printf("Current value:%8.2f\n", val);
}
}
void SYD(void)
{ int n, N, year, choice = 0;
float val, value, deprec, tag;
char answer1 = 'Y', answer2 = 'Y';
printf("\nSum-of-the-Years\'-Digits method\n\n");
tag = val;
for (year = 1; year <= n; year++)
{
deprec = (n-year+1)*tag/(n*(n+1)/2);
val -= deprec;
printf("End of year %2d ", year);
printf("Depreci ation: %7.2f ", deprec);
printf("Current value:%8.2f\n", val);
}
}
thank you...
Comment