In: Computer Science
Look at the C code below. Identify the statements that contain a syntax error OR logical error. Evaluate each statement as if all previous statements are correct. Select all that apply
#include <stdio>
Int main()
{
Float webbing;
Puts(“Please enter the amount of webbing per cartridge: “)
Scanf(“%f”, webbing);
Printf(“You entered: “+ webbing + “\n”);
Return 0;
}
Answers:
Including the library for I/O
Declaring a variable
Writing output to the console using puts
Getting input from the console
Writing output to the console using printf
syntax error in #include<stdio>
.h is missing correct statement is #include<stdio.h>
syntax error in Int and Float
int and float should starts with small letter.
Puts also starts with capital letter correct is puts.
you have to include header file to access puts
#include<string.h>
ambracent is missing in scanf and
Scanf starts with capital letter this is wrong scanf starts with small letter
printf must starts with small letter and format specifier is missing %f. there is no concatenation.
return must starts with small letter. you put “ ” instead of ".
correct program is:
#include<stdio.h>
#include<string.h>
int main()
{
float webbing;
puts("Please enter the amount of webbing per
cartridge: ");
scanf("%f",&webbing);
printf("You entered: %f\n",webbing);
return 0;
}
Output: