Download presentation
Presentation is loading. Please wait.
1
CSCE 206 Lab Structured Programming in C
Spring 2019 HW1 COMMON ERRORS
2
File submission 1 compressed zip file (named as specified in the instructions) containing ONE .c file per question which must be called: HW1_Q1.c Not: LAB1_Q1.c, Problem1.c, HW1_Q1.c.c, hw1_q1.c or anything different Not: everything in a single .c file, that will never compile because of multiple definitions of main() No intermediate folder: compress the 3 files, not a folder containing the 3 files! Sorry for the confusion of HW vs LAB in the naming, I used the same instructions from the previous semester and after publishing the instructions I don’t want to confuse more people by changing it. This shouldn’t be a problem if you correctly create your folders, either in your laptop or the server: 1 folder for the course like “cse206” with two folders, one for “lectures”, another one for “labs” and in labs you have another folder for lab “problems” and another folder for “assignments”. In assignments you will have HW1, HW2, HW3, … If you organize your folders this way everything should be easier and more clear. They MUST compile and run in the linux2 server. It is YOUR responsibility to check that. Be able to compile it and run it in visual studio, online or anywhere else won’t get you the points! Remember, compile and run correctly is 80% of your grade!! The sample inputs and outputs specified in the questions are for you to practice, if they are divided by a line, it means they are different inputs. If it is not specified that you need to run the same program for X number of times, do so just to comply with one input set at a time.
3
Code mistakes Do not change the output. It should be as stated in the question. If it says to output with lowercase, use lowercase If it has a $, put it; if it has “yards” do not write “yd” “Number-1:”, write that and not “what is your first number” No extra printf(), do not write things like “Problem 2:” In the question I put the parts of the output of the program in red to differentiate from the user input. But DO NOT output in red. I will just see weird characters. To specify a number of decimals in printf() in a floating point you need to use %.2f where 2 is the number of decimals, in that case 2, e.g. “18.43” Variables should start in lowercase always Should have meaningful names: if you have 2 items that have price and quantity, just call them “price1”, “quantity1”, “discount”. This makes the program readable AND you can avoid explaining in the comments what each variable means!
4
Code comments As per the instructions in my website you need to put a block comment at the start of the file: Example of a good comment in Q2: // 1yd == 3ft and 1 ft == 12 inch, to convert from inches to yards, I divided the inches by 3*12=36 --> yd = inches/36 Comments are placed on or before the line they are about (never afterwards!) All hardcoded values need to be explained!
5
Code improvement Variable naming is very important to make your program readable Do not use all letters of the alphabet (int a, b, c, d, e), use instead something descriptive like “price1, quantity1, input_inches, … You can do “total = total*sales_tax” instead of creating 2 variables (1 for the first calculation, another one for the second part Always use parenthesis around a long operation that contains multiple operators with different order priorities (e.g. (x*y)+z), even if you know what you are doing, don’t leave it to ‘luck’ Always use “{“ and “}” for EVERY if, else, for, while, … And everything inside the brackets need to go on the same indentation level, including comments! And no extra new lines between the bracket and the function or statement that they belong to: E.g.: if (condition) {
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.