•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,489 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,715 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 463 | Replies: 3
![]() |
Greetings, first time I've posted here. Forgive me if I touch on any taboos unique to this forum. My teacher isn't very good and my textbook is virtually useless or I wouldn't be seeking help on the internet.
I did read the homework sticky, though.
It's basically an exercise in loops and if/else statements.
We're calculating commisions and witholding on sales from a data file we have to access inside the program.
The data file has a setup basically like this, the first number being an employee ID and the second being their sales.
6829 45967.28
1111 25000.11
...
...
2222 22222.00
And the program is as follows, without some of the comments at the beginning that would be used by my teacher.
My progam keeps spitting out that there's a parse error on my if/else lines. I don't have any idea what that might be.
If some of the program doesn't make sense that's because I don't fully understand the uses of everything and I simply imitated what I've seen before.
Thanks in advance, folks.
I did read the homework sticky, though.
It's basically an exercise in loops and if/else statements.
We're calculating commisions and witholding on sales from a data file we have to access inside the program.
The data file has a setup basically like this, the first number being an employee ID and the second being their sales.
6829 45967.28
1111 25000.11
...
...
2222 22222.00
And the program is as follows, without some of the comments at the beginning that would be used by my teacher.
language Syntax (Toggle Plain Text)
#include <stdio.h> #include <math.h> main () { int id; double com, wit, sales; FILE *inp; inp=fopen ("prog2.dat", "r"); while (fscanf (inp, "%d %d", &id, &sales) !=EOF) { if (sales <=30000) {com= (.2*sales)} else {com =6000+(.2*sales)} if (com <=3000) {wit=.05*com} else if (3000<com && com<=6000) {wit=150+(.07*com)} else if (6000<com && com<=10000) {wit=360+(.09*com)} if (10000<com) {wit=720+(.12*com)} printf("ID=%d Commission=$%8.2f Withholding_Tax=$%5.2f\2", id,com,wit); } }
My progam keeps spitting out that there's a parse error on my if/else lines. I don't have any idea what that might be.
If some of the program doesn't make sense that's because I don't fully understand the uses of everything and I simply imitated what I've seen before.
Thanks in advance, folks.
Most of the statements in your if/else code lack a ;
Bunching up the code like that doesn't make it any quicker, but does make it a lot harder (therefore longer) to understand.
Indentation is your friend, make use of it.
> fscanf (inp, "%d %d", &id, &sales)
Unless you have a compiler which will warn you, you need to be especially careful about making sure the control string and the parameters match up (%d doesn't read into a double for example).
Bunching up the code like that doesn't make it any quicker, but does make it a lot harder (therefore longer) to understand.
Indentation is your friend, make use of it.
if (sales <=30000) {
com= (.2*sales);
} else {
com =6000+(.2*sales);
}> fscanf (inp, "%d %d", &id, &sales)
Unless you have a compiler which will warn you, you need to be especially careful about making sure the control string and the parameters match up (%d doesn't read into a double for example).
>main ()
The main function is defined as:
Place your code before the return statement. Anything else is wrong. As it is, you're relying on an obsolescent feature (implicit int) and neglecting to return a value, which is undefined behavior.
>{com= (.2*sales)}
Your formatting is hiding the problem, and the problem is failing to end a statement with a semicolon:
The main function is defined as:
int main ( void )
{
return 0;
}>{com= (.2*sales)}
Your formatting is hiding the problem, and the problem is failing to end a statement with a semicolon:
{com= (.2*sales);} I'm here to prove you wrong.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- We only give homework help to those who show effort (Computer Science and Software Design)
- Dynamic memory allocation homework (C++)
- Need help with Computer Science homework (Computer Science and Software Design)
- Homework Help!! Priority Queue ?? (Computer Science and Software Design)
Other Threads in the C Forum
- Previous Thread: extracting an arbitrary number of numbers from a string
- Next Thread: where is wrong?



Linear Mode