473,387 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

error occur during compilation a program

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(answer1) != 'N')
{
system("CLS");

if(toupper(answer2) != 'N')
{
printf("\nOriginal value: ");
scanf("%f", &value);
printf("Number of years: ");
scanf("%d", &N);
}
printf("\nMethod: (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("invalid entry");
}


printf("\n\nAnother calculation? [Y/N] ");
scanf("%1s", &answer1);
if(toupper(answer1) != '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("\nStraight Line Method\n\n");
deprec = val/n;
for (year = 1; year <= n; year++)
{
val -= deprec;
printf("\nEnd of year %2d ", year);
printf("\nDepreciation: %7.2f ", deprec);
printf("\nCurrent 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("\nDouble Declining Balance Method\n\n");
for (year = 1; year <= n; year++)
{
deprec = 2*val/n;
val = deprec;
printf("End of year %2d ", year);
printf("Depreciation: %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("Depreciation: %7.2f ", deprec);
printf("Current value:%8.2f\n", val);
}
}


thank you...
Mar 21 '10 #1
1 1593
newb16
687 512MB
You, in fact, can. But the output loops forever. Because there is garbage in "n" variable in 'for' loop for year, that you can check by stepping in debugger or using debug print. And garbage is there because you place number of years into variable local to main() function and use local 'n' in other functions, that are not the same.
Mar 21 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
2
by: Mike Fisher | last post by:
I'm seeing an error when I try to run/debug a web service. Although it doesn't happen every time, it does occur more than half of the times I hit F5. It appears to be returned by the the JIT...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
1
by: Chris | last post by:
I built small C# Web and Web Service applications in a training class last week. The applications worked in the class, but when I tried to run them again over the weekend, they both bombed....
1
by: MrMike | last post by:
Hi. Almost every time I run Copy Project to copy my application to my web server I receive the following Compilation Error. Could anyone suggst how I fix this? Thanks....
2
by: rsphere | last post by:
my app is running just fine on my home dev box. no compilation errors at all. when i move the whole file structure to my hosted site i get the following error when opening the main page: ...
2
by: tshad | last post by:
This has been driving me crazy. I have been trying to get the error handling working on my system and can get parts of it working and others won't work at all. I found that you can't access...
20
by: JohnQ | last post by:
The way I understand the startup of a C++ program is: A.) The stuff that happens before the entry point. B.) The stuff that happens between the entry point and the calling of main(). C.)...
3
by: dancer | last post by:
I am using Framework 1.1.4322. Who can tell me why I'm getting this error? My code follows Compilation Error Description: An error occurred during the compilation of a resource required to...
2
by: Axel Gallus | last post by:
I am desperately looking for some resources dealing with error handling in c++. Don't get me wrong.... I have very detailed knowledge of exceptions, assertions and invariants, but what is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.