whats wrong about my program?help me...

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Aug 2009
Posts: 2
Reputation: des6043 is an unknown quantity at this point 
Solved Threads: 0
des6043 des6043 is offline Offline
Newbie Poster

whats wrong about my program?help me...

 
0
  #1
Aug 6th, 2009
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
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,042
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

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

 
0
  #2
Aug 6th, 2009
  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.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 45
Reputation: zalezog is an unknown quantity at this point 
Solved Threads: 11
zalezog zalezog is offline Offline
Light Poster

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

 
0
  #3
Aug 7th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 1
Reputation: sseethalak is an unknown quantity at this point 
Solved Threads: 0
sseethalak sseethalak is offline Offline
Newbie Poster

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

 
0
  #4
Aug 8th, 2009
here is the proper code
Attached Files
File Type: c ONE.C (1.5 KB, 6 views)
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 2
Reputation: des6043 is an unknown quantity at this point 
Solved Threads: 0
des6043 des6043 is offline Offline
Newbie Poster

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

 
0
  #5
Aug 10th, 2009
Thanks all you people help...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC