| | |
whats wrong about my program?help me...
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2009
Posts: 2
Reputation:
Solved Threads: 0
what's wrong about this?
why when i compile,it come out expected primary-expression?
what is that?
why when i compile,it come out expected primary-expression?
what is that?
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<conio.h> main() { float Lab,Mid,Pro,Quiz,Final,Total; printf("\nEnter your mark for Lab:"); scanf("%f",&Lab); printf("\nEnter your mark for Mid Exam:"); scanf("%f",&Mid); printf("\nEnter your mark for Quiz:"); scanf("%f",&Quiz); printf("\nEnter your mark for Project:"); scanf("%f",&Pro); printf("\nEnter your mark for Final Exam:"); scanf("%f",&Final); Total=(10/100.0)*Lab+(15/100.0)*Mid+(5/100.0)*Quiz+(20/100.0)*Pro+(50/100.0)*Final; if(Total>=35) printf("\nyou are passed"); else printf("\nyou are failed"); if(Total>=80) { printf("\nyour is grade A",Total); printf("\nwell done"); } else if(Total>=75) { printf("\nyour grade is A-,%f",Total); } else { printf("\nyou don't get A-,%f",Total); } else if(Total>=70) { printf("\nyour grade is B+,%f",Total); } else { printf("\nyou don't get B+,%f",Total); } else if(Total>=65) { printf("\nyour grade is B,%f",Total); } else { printf("\nyou don't get B,%f",Total); } else if(Total>=60) { printf("\nyour grade is B-,%f",Total); } else { printf("\nyou don't get B-,%f",Total); } else if(Total>=55) { printf("\nyour grade is C+,%f",Total); } else { printf("\nyou don't get C+,%f",Total); } else if(Total>=50) { printf("\nyour grade is C,%f",Total); } else { printf("\nyou don't get C,%f",Total); } else if(Total>=45) { printf("\nyour grade is C-,%f",Total); } else { printf("\nyou don't get C-,%f",Total); } else if(Total>=40) { printf("\nyour grade is D+,%f",Total); } else { printf("\nyou don't get D+,%f",Total); } else if(Total>=35) { printf("\nyour grade is D,%f",Total); } else { printf("\nyou don't get D,%f",Total); } getch(); return 0; }
Last edited by John A; Aug 6th, 2009 at 9:24 pm. Reason: added code tags
C Syntax (Toggle Plain Text)
printf("\nyour is grade A",Total);
When you post code you need to wrapped around code tags to present it in a proper format. See here.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
•
•
Join Date: Oct 2008
Posts: 46
Reputation:
Solved Threads: 11
Well,It also gives me an error.
every where when you have else statements coming ahead of else if statements.
May be we can alter the structure of the program , if suppose you have a candidate getting less than 35, you still get into the if block
here and check for grades.
I also don't under the rationale behind the statements like
I would rather care for my grades than "you don't get" thing.
1st approach:
I would rather have a huge if block which checks whether the toal is greater than 35 and then calculate the grades.
Option 2 :
Well ,you have a set grade for any given marks and a definite increment (5 in your case), So we make an array which holds
marks[] and another array which hold your grades[],it would make things simpler.
Something like this
Give them a rude shock if someone enters marks > 100
and we don't use non standard headers (aka conio.h and the getch() function)
C Syntax (Toggle Plain Text)
syntax error before else
May be we can alter the structure of the program , if suppose you have a candidate getting less than 35, you still get into the if block
C Syntax (Toggle Plain Text)
if(Total>=80) . .
I also don't under the rationale behind the statements like
C Syntax (Toggle Plain Text)
printf("\nyou don't get A-,%f",Total); . . printf("\nyou don't get B,%f",Total); . . printf("\nyou don't get C+,%f",Total);
1st approach:
I would rather have a huge if block which checks whether the toal is greater than 35 and then calculate the grades.
C Syntax (Toggle Plain Text)
const int MINIMUM_PASS_MARKS = 35; if (total >= MINIMUM_PASS_MARKS) { /* and then go on checking for a valid grade*/ } else { /* failed*/ }
Option 2 :
Well ,you have a set grade for any given marks and a definite increment (5 in your case), So we make an array which holds
marks[] and another array which hold your grades[],it would make things simpler.
Something like this
c Syntax (Toggle Plain Text)
#include<stdio.h> int main(void) { const int MAX_MARKS = 100; const int mark_range[] = {80, 75, 70, 65, 60, 55, 50, 45, 40, 35}; const char *grades[] = {"A", "A-", "B+", "B", "B-","C+", "C", "C-", "D+", "D"}; int total = 0; int i = 0; int divisons = sizeof (mark_range) / sizeof mark_range[0]; int passed = 0; /*let 0 represent fail*/ printf("Enter your total "); if (scanf("%d", &total) == 1) { printf("Your total is %d", total); /*Loop through to get your grade*/ for ( i = 0; i < divisons; i++) { if (total >= mark_range[i] && total <= MAX_MARKS) { printf("\nYour grade is %s",grades[i]); passed = 1; break; } } if (passed == 0) printf("\nSorry, you failed."); } else fprintf(stderr, "Error in input"); return 0; }

and we don't use non standard headers (aka conio.h and the getch() function)
Last edited by zalezog; Aug 7th, 2009 at 11:44 am.
![]() |
Similar Threads
- Anyone know whats wrong with this union? (C)
- Can anyone figure out what is wrong in my program? (C++)
- Please help me i dont understand whats wrong with my code (C++)
- im wonderin whats wrong in my work (C++)
- Need Advice on for loops with vowels (Java)
- problems with a C++ program can't seem to compile it (C++)
- Whats wrong with my computer??? (Viruses, Spyware and other Nasties)
- Whats wrong with this class??? (C++)
- Can any1 tell me whatz wrong in this program...this does not show the output!!! (C++)
Other Threads in the C Forum
- Previous Thread: Questions about Snake (game) in C or C++
- Next Thread: New To Turbo C Forum (Some Help Required)
Views: 390 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






