hi, i have just come back to school after 18 years i dont know what
possessed me to think i could learn how to program. i am so
handicapped when it comes to technology. i have tried to figure out
how to post my problem on your message board but i cant figure it out.
(i think maybe i just did)
here is my program it will not "compile" yyyyyyyyyyyyy????????
Code:
#include <stdio.h>
#define students 3
#define exams 4

/* function prototypes */
void minimum( const int[][ exams ], int, int );
void maximum( const int[][ exams ], int, int );
void average( const int[][ exams ], int, int );
void printArray( const int[][ exams ], int, int );

int main()
{

const int studentGrades[ students ][ exams ] =
{ { 77, 68, 86, 73 },
{ 96, 87, 89, 78 },
{ 70, 90, 86, 81 } };

void (*f[4])(int [][ exams ], int, int) =
{printArray,minimum,maximum,average};

int choice;

printf( "Enter a choice:\n");
printf( "0 Print the array of grades\n");
printf( "1 Find the minimum grade\n");
printf( "2 Find the maximum grade\n");
printf( "3 Print the average on all test for each student\n");
printf( "4 End Program\n");
scanf( "%d", choice);

while( choice >= 0 && choice < 4 ){

printf( "Enter a number between 0 and 3, 4 to end: ");
scanf( "%d", &choice);
}

printf( "Program execution completed.");

return 0;

}
void printArray( const int studentGrades[students][ exams ], int
students, int exams )
{
int i;
int j;

printf( "                 [0]  [1]  [2]  [3]" );

for ( i = 0; i < students; i++ ) {

for ( j = 0; j < exams; j++ ) {

printf( "%-5d", studentGrades[ i ][ j ] );

}

}

}
/* Find the minimum grade */
void minimum( const int studentGrades[students][ exams ], int
students, int exams )
{
int i;
int j;

for ( i = 0; i < students; i++ ) {

for ( j = 0; j < exams; j++ ) {

}

}

}

}
/* Find the maximum grade */
void maximum( const int studentGrades[students][ exams ], int
students, int exams )
{
int i;
int j;

for ( i = 0; i < students; i++ ) {

for ( j = 0; j < exams; j++ ) {

}

}

}

}
/* Determine the average grade for a particular student */
void average( const int studentGrades[students][exams], int students,
int exams)
{
int i;

while(i < students){

int sum = 0;
double avg = 0.00;

for ( j = 0; j < exams; j++ )

sum += studentsGrades[ i ][ j ];

avg = static_cast<double>(sum)/exams;

printf( "The average grade for student %d is %.2f", i, avg);

i++;
}
}
what was i thinking please end my misery

2. Using the code tags, and indenting your code helps greatly in debugging not to mention reading it.
It's actually C++ code (not C), if you intended it to be C++ try compiling it with a C++ compiler (ie not a C compiler) or vice versa.

ie:
Code:
avg = static_cast<double>(sum)/exams;
is a C++ cast.

What errors and warnings does your compiler tell you of?

Welcome to the boards by the way

3. i have an example in c++, i guess thats my problem im trying to translate it into c.

4. So your trying to translate an example written in C++ to C?
Usually people scoff and ask why, but since your back at school... Anyway be procedural, as for casts read http://cboard.cprogramming.com/showt...213#post621213 - CornedBee wrote that fantastically.

5. ok im not sure translate is the right word, but yes i need it compile with a c compiler

6. Well then you would need to translate it, C++ and C are different languages although C is a subset of C++ (meaning C++ is a superset of C). ie C compiles as C++ (usually) but C++ does not compile as C.

Try indent the code ie go into notepad (or any texteditor), make all the braces aligned ({ and }), well it's hard to explain - make it look like:

* Useless code babble to demonstrate indenting follows
Code:
#include <stdio.h>

void foo(void * dummy)
{
printf("this is a dummy function");
return;
}

int main(void)
{
int a = 160, b = 80;

foo(NULL);

printf("This a bla blah");
if(a == 170)
{
if(b == 80)
{
printf("a = &#37;d, b = %d", a, b);
}
}
return 0;
}
Then repost your new, nice looking code in codetags - then we can move on (I'd do it but I'm tired :P).

Code:
#define exams 4
#define students 6

void average( const int studentGrades[students][exams], int students,
int exams)
Usually defines and macros are written so they're easily distinguishable from other code. You also can't reuse variable names (in the same scope) again,
after the preprocessor passes, this would become
Code:
void average( const int studentGrades[students][exams], int 6,
int 4)
How much of C have you learnt?

7. Here's your code in code tags:

Code:
#include <stdio.h>
#define students 3
#define exams 4

/* function prototypes */
void minimum( const int[][ exams ], int, int );
void maximum( const int[][ exams ], int, int );
void average( const int[][ exams ], int, int );
void printArray( const int[][ exams ], int, int );

int main()
{

const int studentGrades[ students ][ exams ] =
{ { 77, 68, 86, 73 },
{ 96, 87, 89, 78 },
{ 70, 90, 86, 81 } };

void (*f[4])(int [][ exams ], int, int) =
{printArray,minimum,maximum,average};

int choice;

printf( "Enter a choice:\n");
printf( "0 Print the array of grades\n");
printf( "1 Find the minimum grade\n");
printf( "2 Find the maximum grade\n");
printf( "3 Print the average on all test for each student\n");
printf( "4 End Program\n");
scanf( "%d", choice);

while( choice >= 0 && choice < 4 ){

printf( "Enter a number between 0 and 3, 4 to end: ");
scanf( "%d", &choice);
}

printf( "Program execution completed.");

return 0;

}
void printArray( const int studentGrades[students][ exams ], int
students, int exams )
{
int i;
int j;

printf( "                 [0]  [1]  [2]  [3]" );

for ( i = 0; i < students; i++ ) {

for ( j = 0; j < exams; j++ ) {

printf( "%-5d", studentGrades[ i ][ j ] );

}

}

}
/* Find the minimum grade */
void minimum( const int studentGrades[students][ exams ], int
students, int exams )
{
int i;
int j;

for ( i = 0; i < students; i++ ) {

for ( j = 0; j < exams; j++ ) {

}

}

}

}
/* Find the maximum grade */
void maximum( const int studentGrades[students][ exams ], int
students, int exams )
{
int i;
int j;

for ( i = 0; i < students; i++ ) {

for ( j = 0; j < exams; j++ ) {

}

}

}

}
/* Determine the average grade for a particular student */
void average( const int studentGrades[students][exams], int students,
int exams)
{
int i;

while(i < students){

int sum = 0;
double avg = 0.00;

for ( j = 0; j < exams; j++ )

sum += studentsGrades[ i ][ j ];

avg = static_cast<double>(sum)/exams;

printf( "The average grade for student %d is %.2f", i, avg);

i++;
}
}
Here are some of the problems you have:

• You pointer table should be defined to take const arrays, just like the functions they point to.
• When you use scanf() to read a value into choice, you need the &.
• You have #defines for exams and students. You then use variable names with the same name! Can't do that. #defines in this example are used by the C preprocessor to go through your code and replace every instance of that "variable" with the constatnt number that you give it. Don't use variable names that match a #define'd value.
• In your function definitions, don't declare studentGrades with a first parameter for size. In other words, it should be an array something like this: const int studentGrades[][exams]
• Change the static_cast<double> to (double).

Code:
avg = static_cast<double>(sum)/exams;
Becomes:

Code:
avg = (double)(sum)/exams;
Although you still have to fix exams being a #define'd value and a variable name.

Think that's most of them.

8. MacGyver I'm curious, did you indent that by hand?

9. If I did, it would have looked prettier.

It was already indented (or whatever you would like to call that form ) in his post, but without code tags so the formatting was lost. I just put the tags around it.

10. I'm wondering how you managed to post without code tags.

Edit:
Now I see - all you did was put [CODE][/CODE] at the start of the post and thus missed the whole point of insisting that you use them.

In future, code at the start of your code, and /code at the end of your code, repeated as necessary for each code block.

11. Disable JS?

It was already indented (or whatever you would like to call that form ) in his post, but without code tags so the formatting was lost. I just put the tags around it.
Wow your a smart ducky! I never thought of that

Salem you seem to never be on for more than a second? Do you use the RSS feeds or something? It's like *bang* he's gone, *bang* he's here!?!

12. Originally Posted by Salem
I'm wondering how you managed to post without code tags.
I would respectfully suggest someone "fix" that if it can be done without much effort. For whatever reason people can get away with empty code tags, which is what happened in this case. A requirement that code tags be around some block of text would fix that.... or at least make it slightly harder for this to happen.

13. Why not put the hole post in code tags? Ie a space is kept as a space etc? Or is that just silly?

Originally Posted by MacGyver
I would respectfully suggest someone "fix" that if it can be done without much effort.
Regex FTW

Anyway what compiler are you using jmonster?

14. thnx to everybody. i just got back from class/lab, played around with it and got it to work(crazy). after this class if i live to be a thousand, this is all the c language i think i will ever need. you people rock if u understand this stuff:-)

15. There's not much that is really hard to understand about your program.

You make an array and put some grades in it.

You then go through the array to find the minimum grade.
Then you go through the same array to find the maximum grade.

Then you go through the array again to find the average grade.

These are "standard" operations that are done in many programs, especially going through an array to calculate or find, some piece of data/info.

Pretty soon, it's like tying your shoelaces, ez. C is more difficult than many higher level languages, because it works so closely to the model of the computers architecture, and was designed originally for highly trained professional programmers. The syntax and features of the language reflect that, clearly.

I'm sure looking at your program, you've come to the conclusion that everything you needed to do, could have been done in one simple search through your array; the minimum, maximum and average don't need a separate function or search through the array.

I liked your breaking the algorithm up, however. Excellent start for beginners to practice and learn the importance of doing that, when needed.