Jump to content
  • Advertisement
Sign in to follow this  
three6playa

Assignment for class on C Programming

This topic is 4552 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everybody, I am new to programming and for my class we are supposed to create a simple C program, but me and everybody else in my class is pretty confused about this assignment. We only had a brief chapter to read up on this and I think this assignment is a little ridiculous for being introduced to programming. Next term I will be in a class all about C and C++ programming. The assignment: In your file, write a program that prompts the user to enter the scores for four quizzes each worth a maximum of 100 points. Your program should compute the average score and display this average together with a letter grade based on the following scale: 90-100 A 80-89 B 70-79 C 60-69 D 0-59 F Your program must also check for valid input i.e. the score can not be less than zero or greater than 100. Compile and test your program. So far I got this: /* This program shows grades. */ #include <stdio.h> int main() { printf("Enter a grade.\n"); } it works when I compile it and then when I put ./a.out, Enter a grade. comes up so from there I put { if (grade > 100, < 0) printf("the grade, %f, is too large or too small.\n", grade); else printf("the grade, %f, is within limits.\n", grade); } then when I compile it I get the message ProcessGrade.c:10: parse error before '{' token What is this? I am completely lost with this assignment and my instructor never emails me back and the tutoring program is no help, so I thought ya'll would definitely be able to give me some tips. I've been messing with this assignment for four days now.

Share this post


Link to post
Share on other sites
Advertisement
Sorry, I doubt you'll get much help as homework questions are off-limits and your problems aren't the sort where effective 'hints' can be given.

And that seems maybe a little challenging for an introductory assignment, but not ridiculous.

Share this post


Link to post
Share on other sites
Even though this:
  if (grade > 100, < 0)
feels natural to write, you must specify grade twice and combine them with an 'or' operator ||, like this:
  if (grade > 100 || grade < 0)

Share this post


Link to post
Share on other sites
Just a little hint, take a look at how to use if statements and how the braces go around them.

Besides that since it is a assignment we will not be much help. If you need help with logic or ideas on how to do it, we will help but as for writing or fixing your code, we won't. You will learn more if you find these problems, there is a lot to say for putting in the pain to find your syntax errors.

theTroll

Share this post


Link to post
Share on other sites
Wild_ponter, this is the newbie area, BE NICE. He may have read his book and just did not understand. We can nudge him in the right direction. No reason just to be insulting.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
Wild_ponter, this is the newbie area, BE NICE. He may have read his book and just did not understand. We can nudge him in the right direction. No reason just to be insulting.

theTroll

I agree. At least he obviously have made an attemt solving it for himself. And why force him to read the book when we can just tell him? 'He must learn to RTFM' you might respond, and you have a good point.

Share this post


Link to post
Share on other sites
Hints: I would re-read the sections on if statements, then logical operators, and then braces & statements.

Afterwards, you should be able to fix your problem.

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
Wild_ponter, this is the newbie area, BE NICE.


Except that it isn't.

three6playa, the forum you want is called For Beginners, and is at the top of the forum list.

Also, we don't do homework questions here, although we certainly can help with understanding these sorts of things.

But I will try to be nice and also informative.

"parse error before '{' token" means exactly what it says: there is a "token" (either operator, other punctuation, variable name, keyword... some element of the syntax) on that line which is a '{' (opening brace), and at that point in the code this causes an error in "parsing" (if you don't know what that means, please look it up in a dictionary). Which is to say, you can't put a { at that point.

The problem is simply: sections of code enclosed with { and } are called "blocks". They are expected to nest, and a function consists of just one block. So in the main function, your } on line 9 ends the function. Then you have another { right away on line 10, and that is not inside main - it's an unnamed block of code in the middle of nowhere. You're not allowed to have those.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!