473,796 Members | 2,702 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c program help

6 New Member
Hello, I am trying to create a program that is supposed to calculate and print the average of several grades entered by the user.

The output is supposed to look something like this:
----------------------------------------------------------------------
This program calculates the average of as many grades you wish to enter.



First, enter the number of grades to process: 4


Now enter the 4 grades to be averaged.


Enter grade #1: 90
Enter grade #2: 80
Enter grade # 3: -20
*** Invalid entry. Grade must be 0 to 100. ***
Enter grade #3: 25
Enter grade #4: 54


The average of the 4 grades entered is 62


You have a letter grade of D-
----------------------------------------------------------------------

Here is what I have so far:
-----------------------------------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. int main(void)
  3. {
  4.  
  5. /* Output initial greeting and introduce program */
  6. /* --------------------------------------------- */
  7.  
  8. printf ("This program caluculates the average of as many grades as you wish to enter.\n");
  9.  
  10. /* Declare variables. */
  11.  
  12. int number_of_grades, i, grade;
  13. int grade_total = 0;
  14. int invalid_entry = 0;
  15. float average;
  16. char letter_grade;
  17. char grade_A, grade_AB, grade_B, grade_BC, grade_C, grade_CD, grade_D, grade_F;
  18.  
  19.  
  20. /* Prompt user for number of grades to be entered. */
  21. /* ------------------------------------------------*/
  22.  
  23. printf ("First, enter the number of grades to process: ");
  24. scanf ("%i", &number_of_grades);
  25.  
  26. /* Output appropriate message based on number of grades entered. */
  27. /*---------------------------------------------------------------*/
  28.  
  29. printf ("Now enter the %i grades to be averaged.\n", number_of_grades);
  30.  
  31. for (i = 1; i <= number_of_grades; i++)
  32.  
  33. {
  34.  
  35. /* Prompt user for grades. */
  36. /* ----------------------- */
  37.  
  38. printf ("Enter grade #%i: ", i);
  39. scanf ("%i",&grade);
  40.  
  41.  
  42. /* If grade is out of range (less than zero, OR greater than
  43. 100), output error message, otherwise output grade entered.*/
  44. /* ---------------------------------------------------------- */
  45.  
  46. if (grade > 100 || grade < 0)
  47. {
  48. printf ("*** Invaid entry. Grade must be 0 to 100. ***\n");
  49. i --; 
  50. }
  51.  
  52. else
  53.  
  54. {
  55.  
  56. /* Assign values */ 
  57. /* --------------*/
  58.  
  59. grade_total = grade_total + grade; 
  60. }
  61.  
  62. } // end for loop
  63.  
  64.  
  65. /* Calculate average and display output */
  66. /* ------------------------------------ */
  67.  
  68. average = (float) grade_total / number_of_grades;
  69. printf("\nThe average of the %i grades entered is: %.0f", number_of_grades, average);
  70.  
  71. /* Assign values to letter grades */
  72. /* -------------------------------*/
  73.  
  74. letter_grade = grade_total / number_of_grades;
  75.  
  76. if ( (char) average >= 93 && <= 100) 
  77. {
  78.  
  79. printf ("You have a letter grade of %c\n", grade_A);
  80.  
  81. }
  82.  
  83. else ( (char) average <= 92 && >= 88)
  84. }
  85.  
  86. printf ("You have a letter grade of %c\n", grade_AB); 
  87.  
  88. {
  89. if ( (char) average <= 87 && >= 83)
  90. }
  91. printf (" You have a letter grade of \n", grade_B);
  92.  
  93. {
  94.  
  95. else ( (char) average <= 82 && >= 78)
  96. }
  97.  
  98. printf ("You have a letter grade of\n, grade_BC");
  99.  
  100. {
  101.  
  102. if ( (char) average<= 77 && >= 73)
  103.  
  104. }
  105. printf ("You have a letter grade of C\n");
  106.  
  107. {
  108.  
  109. else ( (char) average <= 72 && >= 68)
  110.  
  111. printf ("You have a letter grade of\n", grade_CD);
  112.  
  113. {
  114.  
  115. if ( (char) average <= 67 && >= 63)
  116.  
  117. }
  118. printf ("You have a letter grade of\n", grade_D);
  119.  
  120.  
  121. else ( (char) average <= 62 && >= 0)
  122.  
  123. }
  124. printf ("You have a letter grade of\n", grade_F);
  125.  
  126. {
  127.  
  128.  
  129. } //end main
  130.  
------------------------------------------------------------------------
The program isn't working and I can't figure out how to fix it. I am getting errors on lines 76,86,91,98,105 ,112,119,and 126. Any help would be much appreciated.

Thanks
Mar 27 '08 #1
1 1604
Banfa
9,065 Recognized Expert Moderator Expert
Normally I would ask you to post the text of the errors, however

this

Expand|Select|Wrap|Line Numbers
  1. if ( (char) average >= 93 && <= 100)
  2. {
  3.    ...
  4. }
  5.  
should be

Expand|Select|Wrap|Line Numbers
  1. if ( (char) average >= 93 && (char) average <= 100)
  2. {
  3.    ...
  4. }
  5.  
you can't short cut expressions in if statements
Mar 27 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
8526
by: anuradha.k.r | last post by:
hi, i am writing a socket program in python,both client side and server side.I've written the client side which is working perfectly fine(checked it against server program written in C).but as for my server program written in python it simply hangs.it does not show any error also.I've tried sample programs available .I don understand what the reason is as i am quite new to it. here is teh server side program: ///////////////////////
2
1785
by: stanlo | last post by:
Hallo to everyone, i am just begining to learn c++ even though i did pascal when i studied mathematics in the univesity.i just took on my self a project which writing a c++ program which does addition, subtraction, multiplication and division.Highest number of input characters should be 80 and the program should output eror meseges like, when division by zero is done,or catch wrong user inputs like letters of the alphabet.Please i have...
7
3301
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that I believe if it's solved, the remaining stuff is easy... my full program until now is here: http://www.geocities.com/tom4_h4wk/progmail.zip the problem is the segmentation fault when main trys to run leficheiro.c.... the *.c2 files are the...
1
2547
by: Willing 2 Learn | last post by:
Below is a program I did to recognize a Finite State Automata for ASCII (J+H)*. I got that one working but im having trouble getting the NFA program to work. I really desperately need help! My NFA has initial states: 2 and 12 ending states 2 and 12 I need help to switch program below from FSA to recognize NFA. I was trying to do a general program so if i have another expression it can be easily changed thus no...
66
5418
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
12
2818
by: asif929 | last post by:
I am trying to write a program which creates four triangles. The program begins with prompting a user " Enter the size of triangles", number from 1 to N is the size of four triangles For Example if we enter 4, the size of four triangles are 4 rows. In addition, I am also writing a program which i started and failed in giving the right size of traingles. I will appreciate if somebody can help.
21
2556
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to run, However, i simply created this program in arrays and it runs good except i cant figure out how to compute the standard deviation. The coding is below. Any help will be appreciated. 1) The Program will prompt the user for six grades to be...
0
1387
by: ashishbathini | last post by:
Hi guys here is my problem ... this is the source code I Have , honestly I hav no idea how it works bcos its too complicated for me .... but my problem is ... i hav a freq comonent in it .... what I have to do with it is ... I need to take the output of the second program (which is the freq component ) and this Shud be the input for the program A i am not sure bout the freq component too ....since i am unable to understand the program...
9
3007
by: C#_Help_needed | last post by:
I need help with the following question. THANKS :) Write a program in c# that takes in a directory as a command line parameter, and returns the longest repeated phrase in ALL text files in that directory. Assume that all contents of all the files may be held in memory at the same time. Do not use unsafe code blocks and/ or pointers.
0
9673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9524
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9047
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7546
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6785
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5568
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2924
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.