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:
----------------------------------------------------------------------- -
#include <stdio.h>
-
int main(void)
-
{
-
-
/* Output initial greeting and introduce program */
-
/* --------------------------------------------- */
-
-
printf ("This program caluculates the average of as many grades as you wish to enter.\n");
-
-
/* Declare variables. */
-
-
int number_of_grades, i, grade;
-
int grade_total = 0;
-
int invalid_entry = 0;
-
float average;
-
char letter_grade;
-
char grade_A, grade_AB, grade_B, grade_BC, grade_C, grade_CD, grade_D, grade_F;
-
-
-
/* Prompt user for number of grades to be entered. */
-
/* ------------------------------------------------*/
-
-
printf ("First, enter the number of grades to process: ");
-
scanf ("%i", &number_of_grades);
-
-
/* Output appropriate message based on number of grades entered. */
-
/*---------------------------------------------------------------*/
-
-
printf ("Now enter the %i grades to be averaged.\n", number_of_grades);
-
-
for (i = 1; i <= number_of_grades; i++)
-
-
{
-
-
/* Prompt user for grades. */
-
/* ----------------------- */
-
-
printf ("Enter grade #%i: ", i);
-
scanf ("%i",&grade);
-
-
-
/* If grade is out of range (less than zero, OR greater than
-
100), output error message, otherwise output grade entered.*/
-
/* ---------------------------------------------------------- */
-
-
if (grade > 100 || grade < 0)
-
{
-
printf ("*** Invaid entry. Grade must be 0 to 100. ***\n");
-
i --;
-
}
-
-
else
-
-
{
-
-
/* Assign values */
-
/* --------------*/
-
-
grade_total = grade_total + grade;
-
}
-
-
} // end for loop
-
-
-
/* Calculate average and display output */
-
/* ------------------------------------ */
-
-
average = (float) grade_total / number_of_grades;
-
printf("\nThe average of the %i grades entered is: %.0f", number_of_grades, average);
-
-
/* Assign values to letter grades */
-
/* -------------------------------*/
-
-
letter_grade = grade_total / number_of_grades;
-
-
if ( (char) average >= 93 && <= 100)
-
{
-
-
printf ("You have a letter grade of %c\n", grade_A);
-
-
}
-
-
else ( (char) average <= 92 && >= 88)
-
}
-
-
printf ("You have a letter grade of %c\n", grade_AB);
-
-
{
-
if ( (char) average <= 87 && >= 83)
-
}
-
printf (" You have a letter grade of \n", grade_B);
-
-
{
-
-
else ( (char) average <= 82 && >= 78)
-
}
-
-
printf ("You have a letter grade of\n, grade_BC");
-
-
{
-
-
if ( (char) average<= 77 && >= 73)
-
-
}
-
printf ("You have a letter grade of C\n");
-
-
{
-
-
else ( (char) average <= 72 && >= 68)
-
-
}
-
printf ("You have a letter grade of\n", grade_CD);
-
-
{
-
-
if ( (char) average <= 67 && >= 63)
-
-
}
-
printf ("You have a letter grade of\n", grade_D);
-
-
{
-
-
else ( (char) average <= 62 && >= 0)
-
-
}
-
printf ("You have a letter grade of\n", grade_F);
-
-
{
-
-
-
} //end main
-
------------------------------------------------------------------------
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
1 1604 Banfa 9,065
Recognized Expert Moderator Expert
Normally I would ask you to post the text of the errors, however
this -
if ( (char) average >= 93 && <= 100)
-
{
-
...
-
}
-
should be -
if ( (char) average >= 93 && (char) average <= 100)
-
{
-
...
-
}
-
you can't short cut expressions in if statements
Sign in to post your reply or Sign up for a free account.
Similar topics |
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:
///////////////////////
|
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...
|
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...
|
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...
|
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...
| |
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.
|
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...
|
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...
|
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.
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |