| | |
Getting a Grade Average
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2004
Posts: 11
Reputation:
Solved Threads: 0
hey everyone. School is finally over (heck yes!) and next semester I'm moving onto C++, kinda nerve recking. I don't have a good C backround yet. So I'm working on some problems from our text book over the holidays. (If anyone has some interesting problems/programs that I could practice they would be appreciated) Anyway, I'm working on a problem now that finds 5 students grades I was wondering if you could help me out with it.
Program that prints the average for each student in the class(I know I'm going to use some arrays and pointers... I just don't know how to set it up)
"A"=4
"B"=3
"C"=2
"D"=1
"F"=0
Number of students is 5(just picked a number)
each student has 4 grades
the user is going to input all the information for each student
calculate grade average
then output information of student(name, id) and the students grade average
Any help would be appreciated... or I'll be stuck on it all break... lol ><
Program that prints the average for each student in the class(I know I'm going to use some arrays and pointers... I just don't know how to set it up)
"A"=4
"B"=3
"C"=2
"D"=1
"F"=0
Number of students is 5(just picked a number)
each student has 4 grades
the user is going to input all the information for each student
calculate grade average
then output information of student(name, id) and the students grade average
Any help would be appreciated... or I'll be stuck on it all break... lol ><
Some ideas:
C++ Syntax (Toggle Plain Text)
#include <stdio.h> struct student { int id; char name [ 32 ]; double grade [ 4 ]; }; void show(struct student *student) { static const char letter[] = "FDCBA"; size_t i; double sum = 0; for ( i = 0; i < sizeof student->grade / sizeof *student->grade; ++i ) { sum += student->grade[i]; } sum /= i; printf("%3d %-31s %c\n", student->id, student->name, letter [ (int)sum ] ); } int main(void) { struct student coder[] = { { 123, "Slim Pickens", {1,2,3,4} }, { 125, "Guy Wire", {2,2,3,2} }, { 128, "MaeFlowers", {0,1,1,1} }, { 132, "June Meadows", {2,1,1,2} }, { 121, "April Showers", {3,3,3,3} }, { 119, "Les Ismoore", {1,2,3,4} }, { 137, "Harry Legg", {3,2,3,3} }, { 142, "Sara Bellum", {4,2,3,4} }, { 159, "Pete Moss", {4,4,4,4} }, }; size_t i; for ( i = 0; i < sizeof coder / sizeof *coder; ++i ) { show(&coder[i]); } return 0; } /* my output 123 Slim Pickens C 125 Guy Wire C 128 MaeFlowers F 132 June Meadows D 121 April Showers B 119 Les Ismoore C 137 Harry Legg C 142 Sara Bellum B 159 Pete Moss A */
![]() |
Similar Threads
- Letter Grade Array (VB.NET)
- Student Grade Programming (C++)
- add and average array (C++)
- grade()...Help (C++)
- average array (C++)
Other Threads in the C++ Forum
- Previous Thread: Vectors, Functions, and Sorting... oh my!
- Next Thread: cin.peek
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






