Question
3. You are given a file named hw01q3.c. All instructions are given in the form of comments in the file. You should correct the errors
3. You are given a file named hw01q3.c. All instructions are given in the form of comments in the file. You should correct the errors and identify which error type they are. Please read all instructions carefully, then complete and submit the updated file.
#include
// CSE 240 Fall 2018 Homework 1 Question 3 (20 points) // Before starting this assignment, please compile and run this program. // You will first notice that the program will not compile. Fix the errors and define the error types. // Next, you will notice that the program is printing incorrect information. Fix the errors and define those error types.
int main(){
// Problem 1: (4 points) // The statement below should cause the program to not compile. Correct the error(s). (2 points).
p = 20.18;
printf("p is equal to %f ", p);
// Define what type of error this is, your answer should replace the space next to "Error Type: " below (2 points). // Your answer should be either Syntactic, Semantic, or Contextual. printf("Error Type: ______ ");
// Problem 2: (4 points) // Half of 50 is 25, why is the program printing that half of 50 is 0? Correct the error(s) (2 points).
int q = 50;
printf("Half of %d is %d ", q, q * (1/2));
// Define what type of error this is, your answer should replace the space next to "Error Type: " below (2 points). // Your answer should be either Syntactic, Semantic, or Contextual. printf("Error Type: _______ ");
//Problem 3 (2 points) //Integer variable y is initialized to 100 and its value needs to be printed. Correct the error(s).(1 point) int y = 100; printf("y is %c ",y); // Your answer should be either Syntactic, Semantic, or Contextual. (1 point) printf("Error Type: ____ "); //Give your explanation here: printf("________ "); // Problem 4: (2 points) // Float variable f has been initialized to 3.14, why does the program seem to think otherwise? Correct the error(s) (2 points).
float f = 3.14;
if (f = 10) printf("f is equal to 10. "); if (f > 10) printf("f is greater than 10. "); if (f < 10) printf("f is less than 10. ");
// Define what type of error this is, your answer should replace the space next to "Error Type: " below (2 points). // Your answer should be either Syntactic, Semantic, or Contextual. printf("Error Type: ______ ");
// Problem 5: (4 points) // Surely, 60 is an even number. Why is the program printing that 60 is an odd number? Correct the error(s) ( points).
q = 60;
if (q / 2 == 0) printf("%d is an even number. ", q); if (q / 2 != 0) printf("%d is an odd number. ", q);
// Define what type of error this is, your answer should replace the space next to "Error Type: " below (2 points). // Your answer should be either Syntactic, Semantic, or Contextual. printf("Error Type: _______ ");
// Problem 6: (4 points) // This bit of code is meant to print "Hello World!". Correct the error(s) (2 points).
printf("Hello %c ", "World!");
// Define what type of error this is, your answer should replace the space next to "Error Type: " below (2 points). // Your answer should be either Syntactic, Semantic, or Contextual. printf("Error Type: _________ ");
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started