Jump to content

My First From Scratch C Program


WhenKittensATK

Recommended Posts

cool! i took a basic programming class as it was part of my Mechanical Engineering degree requirements and i must say i loved it! we programmed in matlab, which is actually a lot more like C than i had originally thought.

 

i don't really have any helpful input, as i'm not very fluent in C but best of luck to you in the rest of the class!

 

btw what are you majoring in?

Share this post


Link to post
Share on other sites

I shalln't do it for you, but:

 

Put in a grade of -0.2

Put in a grade of 100.1

Put in all grades so they're > 100

Put in a grade of abc

 

:P

:lol: I was going to point this out and you beat me to it.

Share this post


Link to post
Share on other sites

why do you have them enter -.1 after all the grades are entered? why not just have them hit enter and the grade be empty and recognize that as the end?

 

He hasn't thought us how to do that yet. This class just started about 2 weeks ago. That's what made it hard to figure it out, because I knew he didn't teach us how to end a loop with a blank. So I just came up with this idea from a previous example. I had the loop stop when the user entered "-0.1." Because -0.1 isn't an actual grade or score anyone could get. So no one would type it in by mistake and it is distinct.

Edited by Krazyxazn

Share this post


Link to post
Share on other sites

That doesn't make any sense.

 

I'm majoring in Computer Science.

what he's saying is what if the grade is 'abc' the next grade is 'def'. Does your program accept them as valid grades to be input? Are the grades <0 valid grades? What about >100?

 

Remember, users are dumb. If they can do something wrong they will.

 

He hasn't thought us how to do that yet. This class just started about 2 weeks ago.

ok, fair enough.

Share this post


Link to post
Share on other sites

what he's saying is what if the grade is 'abc' the next grade is 'def'. Does your program accept them as valid grades to be input? Are the grades <0 valid grades? What about >100?

 

Remember, users are dumb. If they can do something wrong they will.

 

Grades 0 - 100 work. If you got extra credit like something 115. It will only work if your average sum isn't over 100. I didn't make it to enter test grades though. I could add it in (at least I think I could, we haven't done any actual word inputs yet. we mostly just did number inputs so far), just never thought of it. The teacher just wanted us to make a program for test grade numbers that, output average score and grade letter.

 

 

what he's saying is what if the grade is 'abc' the next grade is 'def'. Does your program accept them as valid grades to be input?

Good point, never thought of this. My program wouldn't accept multiple entries in one printf/scanf session. He hasn't taught us how to do that one either. I'll word my printfs more specific next time. EX. (Enter your first test grade, then enter your next test grade). Hopefully from the words "first" and "grade" users will realize that they are suppose to only enter one grade at a time. I'll also put up only test grades 0 - 100 are valid, so they know its your test score percentage not letter grade.

 

Thanks for the input. It will help me get my next assignment more anti-user mistakes. If there is other stuff I failed to see, let me know. I'm still a beginner and trying to figure things out as I go.

Edited by Krazyxazn

Share this post


Link to post
Share on other sites

I realize that this is your first program but they are some things to keep in mind. Like what happens if I'm just not paying attention and enter a grade of 'a' or accidentally hit '9o' (nine and the letter o) just try it, though you'll want to remember to end a program you can also use ctrl+c.

Not sure if you've covered this yet in class but take a peek at the return values of scanf. You can view this by typing 'man scanf' into your terminal window. Again, I'm not sure how much your teacher wants you to do but you could impress him by going a bit further. If you need more help just let us know.

Share this post


Link to post
Share on other sites

No, what I was saying is:

 

It'll accept non-number input and blow up rather nicely.

It'll also accept a grade of less than 0.0 (unless it's 0.1). Try -0.2 for instance.

It'll accept a grade above 100.0

If the average grade is bigger than 100.0 - which is currently possible, as you accept grades > 100.0 - nothing at all will be printed out at the end.

 

You could also use a do-while loop to avoid a bit of code duplication.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...