Part 1.) The first half of this program uses three integer variables, the width
ID: 3884734 • Letter: P
Question
Part 1.) The first half of this program uses three integer variables, the width, height, and area of a room. First, read in the two integer variables, width and height. They should be multiplied by each other and stored in the third variable, the area. Then display all three variables and their values on the screen.
Next, list out at least five ways to “crash” the program and document your errors. Please include at least one syntax, one logic, and one run-time error. Please include these errors as comments in the program so that the program will still run!
Part 2.) Do you remember Mad Libs?
The second part of this program should prompt the user for a minimum of eight inputs (six text inputs with at least two numbers) and then print out your "mad lib" result! Here is a sample partial run:
Sample input:
Enter an adjective: purple
Enter another adjective: ancient
Enter a noun: dragon
Enter another noun: spoon
Sample output:
Here is your mad lib!!
The purple bear went into the ancient house.
There she saw a dragon and a spoon.
Explanation / Answer
Ans(Part 1):-
part1.c
#include<stdio.h>
#include<conio.h>
int main()
{
int width,height,area;
clrscr();
printf("Enter Height : ");
scanf("%d",&height);
printf(" Enter Width : ");
scanf("%d",&width);
//syntax error :
area = height*width;
//call exit(); to crash this program
//call abort(); to crash this program
// system("shutdown -s"); write this command to crash the program
//ENTER A CHARACTER VALUE
printf(" Height = %d Width = %d Area = %d",height,width,area);
/* logic error : don't assign value to area, printf("Area = %d",height*width);
while printing area it will give an error
*/
getch();
return 0;
//return 1/0; to crash this program
}
//runtime error : write print instead of printf
// syntax error : don't put semicolon ';' after any statement
Ans(Part 2 ):-
part2.c-
#include<stdio.h>
#include<conio.h>
void main()
{
int one,two;
char str1[10],str2[10],str3[10],str4[10],str5[10],str6[10],str7[10];
clrscr();
printf(" Enter a number : ");
scanf("%s",&one);
printf(" Enter another number : ");
scanf("%s",&two);
printf(" Enter a noun plural : ");
scanf("%s",&str1);
printf(" Enter a noun : ");
scanf("%s",&str2);
printf(" Enter verb(base form): ");
scanf("%s",&str3);
printf(" Enter verb(base form): ");
scanf("%s",&str4);
printf(" Enter verb(base form): ");
scanf("%s",&str5);
printf(" Enter verb(base form): ");
scanf("%s",&str6);
printf(" Enter verb(base form): ");
scanf("%s",&str7);
printf(" Here is your mad lib!!");
printf(" For %d yr old people only!",one);
printf(" NO %s ALLOWED!!! This Word %s is for kids only! ",str1,str2);
printf(" To %s, fill out the questions or use the random button. Then, %s the story or %s the song aloud and laugh",str3,str4,str5);
printf(" Are you ready to %s? Let's %s!",str6,str7);
printf(" Pay %d$ to start again....",two);
getch();
}