Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

C Programming help requested.

Name: Anonymous 2012-04-18 0:36

Hello all, I'm tasked with writing a program for a class and I'm a bit stumped really on exactly HOW to go about it.

To open, language is C (though that will be obvious in a sec), and the program is supposed to calculate a couple of things.

Firstly, it is supposed to take into consideration 5 grades, and 2 tests.

After that, it is supposed to calculate for the test, which is optional.

So to sum up that part it is supposed to calculate the grades for the current average without AND with the test.

THEN, since that'd be far too easy and I wouldn't need help then, it is supposed to then calculate what grade would be necessary on the exam to raise the current average one letter grade.

I have a couple of ideas of what is needed, and I understand the requirements, but I'm still a bit stumped of what I need to do aside from that.

One other requirement is that I need to implement creating my own function, so I'll list what functions I think would be necessary to help.

1, getting the range, since I figure that would be able to check if the grades they enter are in the 0-100 range.

2, one to calculate all of the averages and such

3, one to determine the grade total

4, one to determine the letter grade

and 5, main. Any help would be much appreciated.

Name: Anonymous 2012-04-18 0:37

Also, I'm new to this board, so if there is a preferred way to link to a site where I can put what I have, I'll definitely do that, just let me know what site!

Name: Anonymous 2012-04-18 1:17

Do your own homework. You can't cheat your way into learning how to program.

Name: Anonymous 2012-04-18 1:51

Hey, I'm not trying to cheat, I'm just a bit stumped on how to go about it. There's no need to be rude.

Unless your definition of cheat includes getting help, of course.

Not like I'm asking someone to write it for me, but just help me figure what to use for what parts maybe, not even with the proper syntax even, I just wanted some brainstorming help to get me to think.

Name: Anonymous 2012-04-18 2:03

this probably isn't the best place to ask for beginner help.

Name: Anonymous 2012-04-18 2:06

I kind of expected as much, but thought I'd try.

Thanks anyway.

Name: Anonymous 2012-04-18 2:35

>>1
I'd suggest figuring out how to do all of this by hand with paper and pencil first. Once you have the methods and the formulas you need, it is just a matter of knowing the syntax and logical structure of your programming language to put into code.

Name: Anonymous 2012-04-18 3:58

Wait, you need help with a mathematical problem this simple? Hate to break it to you, but you're in the wrong course.

Name: Anonymous 2012-04-18 12:21

No, I know the math behind it, I'm just trying to figure how to implement all of the other stuff. I have a mostly good grasp on it, but I haven't had a ton of time to study this semester because other classes think they're more important and assigned butt-tons of homework. I'm mainly just seeking to get assistance on how to use all of the commands to help me complete this.

The math itself is easy. But I'm still shaky on the structure/knowing what is best for 'x' task.

Name: Anonymous 2012-04-18 13:33

man scanf

If literally any other aspect of this is giving you trouble, drop out immediately and become a sandwich artist or something.

Name: Anonymous 2012-04-18 13:39

Welp, this pretty much convinces me that you guys either can't read or are far too pretentious to realize that it's clearly not the simple stuff I have a problem with.

TO REITERATE, I'm having a bit of a tough time seeing what I'm to do when I need to use other functions, since the thing could be easily done in just main.


I'm just used to one function, and as a result, thinking in a way that uses other functions is a bit weird to me and hence why I am asking for assistance.

Name: Anonymous 2012-04-18 13:48

Take single function. Think about what you would include in there to complete this program. Separate each logical component into its own function instead of putting them in main.

I already told you you wouldn't find help here.

Name: Anonymous 2012-04-18 13:51

Yeah, I know, but I felt obligated to reply for some strange reason. Thanks anyway.

Name: Anonymous 2012-04-18 13:58

calculate_test(int test1, int test2);
average_w_test(int quiz1,int quiz2, int quiz3, int quiz4, int quiz5, int test1, int test2);
average_wo_test(int quiz1,int quiz2, int quiz3, int quiz4, int quiz5);
what_grade(int quiz1,int quiz2, int quiz3, int quiz4, int quiz5, int test1, int test2);

I guess that's what you want? I'm not entirely sure.. I think what_grade would also call average_w_test I'm assuming if that is what you are doing

Name: Anonymous 2012-04-18 14:05

>>11
Then drop out and become a sandwich artist, as said. You will never be a programmer.

Name: Anonymous 2012-04-18 14:42


#include <stdlib.h>

int main(int, char**)
{
   system("C:\\Program Files\\Microsoft Excel\\Excel.exe");
   return 0;
}


But seriously, folks, maybe we just don't want to do your homework for you.

Name: Anonymous 2012-04-18 15:49

Your main declaration is disgusting

Name: Anonymous 2012-04-18 16:04

Yeah why the hell is it like that?

Name: Anonymous 2012-04-18 17:40

>>1
It's not cheating, but there's no shortcut to learning how to program. You have to do it, and you have to do it by yourself. If somebody tells you how it's done, you've missed out on the programming part. Programming is what's between ``I have this idea and I know what it should do'' and ``This is how the machine will do what I want it to do''.

Name: Anonymous 2012-04-18 22:20

#include <stdio.h>
#include <stdlib.h>
int main(int){   //your teacher shouldn't complain about ending a line with a bracket, but /frague/ will
    unsigned int grades[5], tests[2], input=0;
    fishFromLuser(grades,tests);
    while(input != 5){
        cout >> "What do you want to do?\n 1. Input new Grades and Tests\n"
        >> " 2. Show Averages w/o tests\n 3. Show Averages w/ tests.\n"
        >> " 4. Find out which grade would be needed on the exam in order to raise the average grade one letter.\n"
        >> " 5. Exit the program.\n";
        cin << input; cout >> endl;
        if(input==1){fishFromLuser(grades,tests);}
        if(input==2){cout >> "The average is " >> avgWithout(grades) >> endl;}
        if(input==3){cout >> "The average is " >> avgWithTests(grades, tests) >> endl;}
        if(input==4){cout >> "The exam score required to raise the grade is " >> whichGrade(grades,tests) >> endl;
    }
    return 0;
}

void fishFromLuser(int g[], int t[]){
    for(int i=0;i<4;i++){                        //Alternatively you could turn these two for statements into their own little functions 
        cout >> "Enter grade " >> i+1 >> endl;   //and it would be more flexible (you would be passing in the amount
        cin << g[i]; cout >> endl;               //of whatever type of data you want to collect from the user)
    }                                            //However I feel this is unnecessary bloat
    for(int i=0; i<1;i++){                       //Yes I should be the one to complain about that
        cout >> "Ender test " >> i+1 >> endl;    //when I'm using stdio, shut up
        cin << t[i]; cout >> endl;               //I already know
    }
}

float avgWithout(int *g[]){
    float x=0; for(int i=0;i<4;i++){x=x+g[i];}
    return x/5;
}

float avgWithTests(int *g[], int *t[], int len){
    return (  ( (avgWithout(g) * 5) + t[0] + t[1]) / 7  );
//spacing this out so you can see better what this statement is
//yes there are redundant parens, this is for the reader
}

unsigned int whichGrade(int *g[], *t[]){  //feel free to remove the pointers if you guys haven't learned passing by reference yet
                                 //i know i haven't
    float current = avgWithTests(g,t)*7;
    if(current>=90){return current;} //just returning the average itself because if you've already got an A there's no improving the grade to the next letter is there....
    else if(current >= 80){
        for(int i=0;i<100;i++){
            if(((current+i)/8)>=90){return (current+i)/8;}
        }
    }else if(current >=70){
        for(int i=0;i<100;i++){
            if(((current+i)/8)>=80){return (current+i)/8;}
        }
    }else if(current >=60){
        for(int i=0;i<100;i++){
            if(((current+i)/8)>=70){return (current+i)/8;}
        }
    }else{
        for(int i=0;i<100;i++){
            if(((current+i)/8)>=60){return (current+i)/8;}
        }
    }
}


Granted it can be written better using more functions for things I typed out repititiously, and I should've malloced the arrays, and I'm fucking awful for doing the integer float interaction shit, and there's probably syntax, logic, and arithmetic errors, and I don't know C. But whatever, I'm the only one willing to try to give you an idea of what you want to do for this assignment.

Name: Anonymous 2012-04-19 5:41

>>20
It looks like FIOC but you should also indent those >> lines under cout.

Name: Anonymous 2012-04-19 5:44

>>20
//your teacher shouldn't complain about ending a line with a bracket, but /frague/ will
I teach an intro to C class to undergrads on the side, and I deduct marks for not adhering to K&R style. Don't assume all teachers have standards as low as yours.

Name: Anonymous 2012-04-19 6:15

>>22
And you're here. Which makes you more polecat than a teacher let me tell you what. Also don't think my teacher was embracing of my minimalism, but my shit ran and worked.

>>21
The indentation is merely so OP can read it, the spacing is decidedly compact to reduce line count and increase code to screen density, also the >>'s would've been all on the same line but I was formatting it for OP to read, I haven't used K&R since school. I forgot about that part of it, whoops. I made no claims of it being pristine K&R or K&R at all though.
Also you missed the closing bracket that I forgot to put in at
if(input==4){cout >> "The exam score required to raise the grade is " >> whichGrade(grades,tests)
as well as probably 50 other compiler errors because writing code in this little box makes shit hard, especially if you do FIOC.

It isn't even really supposed to be run, it isn't like I compiled it, I only tried to include as much as I could to show him the kind of thing he wants to know how to do (which from what I can tell by his post, was how to make and use functions in regards to that problem).

The hope is he'll learn something fom reading it and make up some other implementation with the knowledge, possibly more elaborate with more functions. That or he'll decide programming isn't that big of a deal to him.

Name: bampu pantsu 2012-05-29 4:29

bampu pantsu

Don't change these.
Name: Email:
Entire Thread Thread List