![]() |
|
#1
|
|||
|
|||
Help me with the end of the coding..the calculationDear friends,i've done a project for my course.Its about employee salary deductions...my only problem is the coding is working but its not doing the deduction and give the balance of a salary for an employee....plz help me plz..
this is the code: CPP / C++ / C Code:
below is the example of the output... ![]() |
|||
|
#2
|
|||
|
|||
Re: Help me with the end of the coding..the calculationQuote:
Quote:
So---If you would like some help, here's the deal:
You should also tell us what compiler you are using. Tell us whether you get any messages from the compiler. Any messages at all. Maybe then someone can help you understand how to find and correct the many errors in the program. Regards, Dave |
|
#3
|
|||
|
|||
Re: Help me with the end of the coding..the calculationThanks alot Dave for the reply..
Ask u asked... 1)My program shows the output as below : ![]() 2)I suppose i want the output to be like this.. ![]() My system works correctly until the the output line is "Your name:" After that it need to do the calculation...so its not doing the exact calculation at all..i know i did some mistake in coding and im very beginner....i would like to know if someone can guide or try to complete the last coding so that it will give the correct output as i want....and with that i can learn from it..as it is my final semester project Im using Microsoft Visual C++ 6.0 and the file name is saved as .c The errors that shown to me now is: project.c D:\Project\project.c(93) : warning C4244: 'initializing' : conversion from 'double ' to 'int ', possible loss of data D:\Project\project.c(93) : warning C4700: local variable 'total' used without having been initialized D:\Project\project.c(101) : warning C4700: local variable 'earning' used without having been initialized D:\Project\project.c(113) : warning C4700: local variable 'federal' used without having been initialized D:\Project\project.c(113) : warning C4700: local variable 'hospital' used without having been initialized D:\Project\project.c(117) : warning C4700: local variable 'total_deduct' used without having been initialized Linking... project.exe - 0 error(s), 6 warning(s) |
|
#4
|
|||
|
|||
Re: Help me with the end of the coding..the calculationFirst get rid of non standard header
CPP / C++ / C Code:
Let's look at this line Quote:
The datatype of total is double. Quote:
and the format specifier ,since it is double should not be %d ( that's for integers)should be %lf for doubles. Something like this (now you don't need braces) CPP / C++ / C Code:
Code:
A similar argument for CPP / C++ / C Code:
earning , total .... Quote:
May be this program can be done better with some helper functions. |
|
#5
|
|||
|
|||
Re: Help me with the end of the coding..the calculationQuote:
I strongly recommend that, for debugging purposes, you print out all input values as the program reads them: Right after your statement reads the value of day print out the value. CPP / C++ / C Code:
Same for hour, month, earn, and all variables whose values you get from the user. Note that the format specifier for scanning a double is "%lf" not "%d". The format specifier for printing a double is "%f", not "%d" Now, look at the line flagged by the first two warnings: Code:
Why did you create a new variable in that block named "earning" ??? You already have a variable named "earning" which is visible everywhere else in the program. By creating a new variable in the block (lines 92--94) you are "hiding" the one that you want to use inside that block, and the local variable inside that block is no longer valid after the program progresses beyond the end of that block. So: delete the '{' and '}' lines (or comment them out) and change your assignment statement to CPP / C++ / C Code:
Compile again, and at least the first warning should go away. Now look at the second warning that you showed: Code:
I'm thinking it is still there. What the heck does it mean? Well look at some statements before your original line 93: CPP / C++ / C Code:
By creating a block and declaring a variable, "total," inside that block you have "hidden" the real "total" variable that was declared at the beginning of the program and you assigned a value to the local variable inside the block. After the program progresses beyond that particular block, the value is lost, and the overall "total" still hasn't been assigned a value. So, again, you can eliminate the "{" and "}" or comment them out, and do not declare a new local variable: CPP / C++ / C Code:
Work your way through all of the warnings. You shouldn't see any messages at all from the compiler. See Footnote. Sometimes compilers give warnings that a knowledgeable might want to ignore. For now, your goal should be to eliminate all warnings. That won't guarantee that the program will work the way that you intended, and, in fact there are a number of problems in your code that do not cause warnings from your particular compiler, but I think that getting rid of compiler warning messages is an important first step. Debugging code and figuring out how to use compiler messages to help you see problems is a learned skill. I mean, no one was born knowing this stuff. Regards, Dave Footnote: Sometimes the compiler messages may not make sense (at least not until you have seen them about a million times), but they should make you look really hard at lines that they tell you about. Sometimes the actual problem may be somewhere in the file before the one that is flagged, so you have to look at everything. |
|
#6
|
|||
|
|||
Re: Help me with the end of the coding..the calculationHello Guys....im done with the project..its working very well...
this is the coding i would like to share with u all...if got any problems,do let me know...im so satisfied now CPP / C++ / C Code:
|
Recent GIDBlog
Problems with the Navy (Chiefs) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Coding style and guideline | ahbi82 | MS Visual C++ / MFC Forum | 0 | 24-Sep-2009 00:46 |
| Run exe file in C++ coding | sitha | C++ Forum | 4 | 02-Mar-2007 00:19 |
| Coding Contest #1 | davis | Miscellaneous Programming Forum | 0 | 12-Jun-2006 09:29 |
| Pls help in this coding. | harsha | C++ Forum | 5 | 08-Apr-2004 21:48 |
| C Coding Style | dsmith | Miscellaneous Programming Forum | 10 | 24-Feb-2004 07:23 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The