you can assume that the user: • Will always enter lower-case answers (or legal,
ID: 3673057 • Letter: Y
Question
you can assume that the user: • Will always enter lower-case answers (or legal, non-negative numbers) to the questions • Will always enter a single-word answer to the questions • The complete set of possible inputs that you could see with this program is shown below shirt, pants, other, t-shirt, nice, sweatshirt, jeans, socks, fine, marginal, bad, none, small, lots As an example of the execution of this program, consider the two instances shown below. Program prompts are shown in blue and the user’s input is shown in red. What are you considering? shirt What kind? t-shirt How does it smell? fine Are there any stains on it? none You can wear this What are you considering? pants What kind? jeans How many times have you worn them? 7 How does it smell? bad You need to wash this We recommend writing functions for the basic questions that get asked on a regular basis. These four functions are: What Kind? and Smell Test and Stains Test and Times Worn. Each of these functions would ask the user a question, read the user’s input, and the return a value to the calling routine. The exact wording of the question is not important; you can phrase it as you want as long as the user knows what the expected answer should be. What You Need To Do • Create a directory called project2 on your machine. In that directory, create a file named wash.c • In wash.c, write the code needed to solve the problem stated above. Make sure that your program o Has a header block of comments that includes your name and a brief overview of the program o Follows the rules specified in the flowchart o Use at least four functions (and has a brief comment describing the purpose of each function). o Clearly prints either Wash it or Wear it at the end of the program • You may assume that the user will always enter valid input. • We strongly recommend that you use scanner.h and scanner.c for all your input.
Explanation / Answer
/* wash.c */
/*
Put Detail here that is demanded like name and brief description of yourself
This program ask a question fromthe user using a function and return the given input by the user using the concept of pointers.
In the calling module i.e. main(), we can test the answers value as per rule and give the result whether it is need to be washed or can be
weared by the user.
*/
#include<conio.h>
#include<stdio.h>
char * consider()
{
char *ans;
textcolor(BLUE);
cprintf(" What are you considering ? ");
textcolor(RED);
cscanf("%s",ans);
return(ans);
}
char * kindTest()
{
char *ans;
textcolor(BLUE);
cprintf(" What kind? ");
textcolor(RED);
cscanf("%s",ans);
return(ans);
}
int TimesWorn()
{
int n;
textcolor(BLUE);
cprintf(" How many times have you worn them? ");
textcolor(RED);
cscanf("%d",&n);
return(n);
}
char * smellTest()
{
char *ans;
textcolor(BLUE);
cprintf(" How does it smell?");
textcolor(RED);
cscanf("%s",ans);
return(ans);
}
char * stainTest()
{
char *ans;
textcolor(BLUE);
cprintf(" Are there any stains on it? ");
textcolor(RED);
cscanf("%s",ans);
return(ans);
}
void main()
{
char *ans1,*ans2,*ans3,*ans4;
int ans5;
clrscr();
ans1=consider();
ans2=kindTest();
ans3=smellTest();
ans4=stainTest();
ans5=TimesWorn();
/* use the Rules given in your flowchart for testing the conditions as per answers and give the response to the user*/
if(stcmp(ans3,"good" )==0 && srcmp(ans4,"none"))
{
textcolor(BLUE);
cprintf("You can wear It ");
}
else
{
textcolor(BLUE);
cprintf("You need to Wash it ");
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.