943,522 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 503
  • C RSS
Aug 6th, 2009
0

whats wrong about my program?help me...

Expand Post »
what's wrong about this?
why when i compile,it come out expected primary-expression?
what is that?



  1. #include<stdio.h>
  2. #include<conio.h>
  3. main()
  4. {
  5. float Lab,Mid,Pro,Quiz,Final,Total;
  6.  
  7. printf("\nEnter your mark for Lab:");
  8. scanf("%f",&Lab);
  9. printf("\nEnter your mark for Mid Exam:");
  10. scanf("%f",&Mid);
  11. printf("\nEnter your mark for Quiz:");
  12. scanf("%f",&Quiz);
  13. printf("\nEnter your mark for Project:");
  14. scanf("%f",&Pro);
  15. printf("\nEnter your mark for Final Exam:");
  16. scanf("%f",&Final);
  17.  
  18. Total=(10/100.0)*Lab+(15/100.0)*Mid+(5/100.0)*Quiz+(20/100.0)*Pro+(50/100.0)*Final;
  19.  
  20.  
  21. if(Total>=35)
  22. printf("\nyou are passed");
  23. else
  24. printf("\nyou are failed");
  25.  
  26. if(Total>=80)
  27. {
  28. printf("\nyour is grade A",Total);
  29. printf("\nwell done");
  30. }
  31. else if(Total>=75)
  32. {
  33. printf("\nyour grade is A-,%f",Total);
  34. }
  35. else
  36. {
  37. printf("\nyou don't get A-,%f",Total);
  38. }
  39. else if(Total>=70)
  40. {
  41. printf("\nyour grade is B+,%f",Total);
  42. }
  43. else
  44. {
  45. printf("\nyou don't get B+,%f",Total);
  46. }
  47. else if(Total>=65)
  48. {
  49. printf("\nyour grade is B,%f",Total);
  50. }
  51. else
  52. {
  53. printf("\nyou don't get B,%f",Total);
  54. }
  55. else if(Total>=60)
  56. {
  57. printf("\nyour grade is B-,%f",Total);
  58. }
  59. else
  60. {
  61. printf("\nyou don't get B-,%f",Total);
  62. }
  63. else if(Total>=55)
  64. {
  65. printf("\nyour grade is C+,%f",Total);
  66. }
  67. else
  68. {
  69. printf("\nyou don't get C+,%f",Total);
  70. }
  71. else if(Total>=50)
  72. {
  73. printf("\nyour grade is C,%f",Total);
  74. }
  75. else
  76. {
  77. printf("\nyou don't get C,%f",Total);
  78. }
  79. else if(Total>=45)
  80. {
  81. printf("\nyour grade is C-,%f",Total);
  82. }
  83. else
  84. {
  85. printf("\nyou don't get C-,%f",Total);
  86. }
  87. else if(Total>=40)
  88. {
  89. printf("\nyour grade is D+,%f",Total);
  90. }
  91. else
  92. {
  93. printf("\nyou don't get D+,%f",Total);
  94. }
  95. else if(Total>=35)
  96. {
  97. printf("\nyour grade is D,%f",Total);
  98. }
  99. else
  100. {
  101. printf("\nyou don't get D,%f",Total);
  102. }
  103.  
  104. getch();
  105. return 0;
  106. }
Last edited by John A; Aug 6th, 2009 at 9:24 pm. Reason: added code tags
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
des6043 is offline Offline
4 posts
since Aug 2009
Aug 6th, 2009
0

Re: whats wrong about my program?help me...

  1. printf("\nyour is grade A",Total);
Take a look at that one. Figure what are you missing.

When you post code you need to wrapped around code tags to present it in a proper format. See here.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Aug 7th, 2009
0

Re: whats wrong about my program?help me...

Well,It also gives me an error.
  1. syntax error before else
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
  1. if(Total>=80)
  2. .
  3. .
here and check for grades.

I also don't under the rationale behind the statements like
  1. printf("\nyou don't get A-,%f",Total);
  2. .
  3. .
  4. printf("\nyou don't get B,%f",Total);
  5. .
  6. .
  7. printf("\nyou don't get C+,%f",Total);
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.
  1. const int MINIMUM_PASS_MARKS = 35;
  2. if (total >= MINIMUM_PASS_MARKS) {
  3. /* and then go on checking for a valid grade*/
  4. }
  5. else {
  6. /* failed*/
  7. }

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
  1. #include<stdio.h>
  2.  
  3. int main(void) {
  4. const int MAX_MARKS = 100;
  5. const int mark_range[] = {80, 75, 70, 65, 60, 55, 50, 45, 40, 35};
  6. const char *grades[] = {"A", "A-", "B+", "B", "B-","C+", "C", "C-",
  7. "D+", "D"};
  8. int total = 0;
  9. int i = 0;
  10. int divisons = sizeof (mark_range) / sizeof mark_range[0];
  11. int passed = 0; /*let 0 represent fail*/
  12.  
  13. printf("Enter your total ");
  14. if (scanf("%d", &total) == 1) {
  15. printf("Your total is %d", total);
  16. /*Loop through to get your grade*/
  17. for ( i = 0; i < divisons; i++) {
  18. if (total >= mark_range[i] && total <= MAX_MARKS) {
  19.  
  20. printf("\nYour grade is %s",grades[i]);
  21. passed = 1;
  22. break;
  23. }
  24. }
  25. if (passed == 0)
  26. printf("\nSorry, you failed.");
  27. }
  28. else
  29. fprintf(stderr, "Error in input");
  30. return 0;
  31. }
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)
Last edited by zalezog; Aug 7th, 2009 at 11:44 am.
Reputation Points: 53
Solved Threads: 13
Light Poster
zalezog is offline Offline
47 posts
since Oct 2008
Aug 8th, 2009
0

Re: whats wrong about my program?help me...

here is the proper code
Attached Files
File Type: c ONE.C (1.5 KB, 9 views)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sseethalak is offline Offline
1 posts
since Aug 2009
Aug 10th, 2009
0

Re: whats wrong about my program?help me...

Thanks all you people help...
Reputation Points: 10
Solved Threads: 0
Newbie Poster
des6043 is offline Offline
4 posts
since Aug 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Mastermind program
Next Thread in C Forum Timeline: NEED Help ASAP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC