punishment2.c E myUCMerced: Students Mail - bmobley@ucmercedFiles ? ? ?fù ?https
ID: 3906843 • Letter: P
Question
punishment2.c
E myUCMerced: Students Mail - bmobley@ucmercedFiles ? ? ?fù ?https://catcourses.ucmerced.edu/courses/10904/files/folder/Labs Lab%2096230?preview-1491756 CSE31,_lab0.pdf X C Chegg Study | Guided SolutC Sign In or Sign Up | Chegg. Download Info X Close Page4 of 5 (Exercise) Create -punishment2.c Since w want to mak?the punishment more realistic, wo will add a typo in one of the lines of the punishment. This is very similar to what you have already done in punishmenti.c, so it would be a good idea to copy your punishment1.c and start from there. Your new program (punishment2.c) will ask the user for the number of lines for the punishment: Enter the number of lines for the punishments Once again, if an incorrect value has been entered, your program should output You entered an incorrect value for the number of lines! and stop executing (up to this point, you should not have to change anything from your last exercise. Next, the program will ask on what line a typo should be made by outputtingg Enter the line for which we want to make a typo: to the screen. Once again, you should check that the value entered by the user is correct (think about what would constitute an incorrect value). If the value is incorrect, display You entered an incorrect value for the line typol and stop program execution. If both inputs are correct, you should then display the punishment sentence the correct number of times (C programming language is the best!), making sure to change it to C programming language is the bet! (the typo) for the line number defined by the user/input. Here are the examples of the output (input is in italic and bold): Enter the number of lines for the punishment 4 Entar the lina for which we want to maka a typo: 1 C programminglanguage is the bet! C programming languspe is the best C programming languoge is the best! C programming language is the best Enter the number of lines for the punishment Enter the line for which we want to make a typo: 3 C programming language ia the beat! programming languaga ia tha best! Cprogramming languaga la the bat programming languaga ia the bert programming language the bast C programming language is the best O Type here to search 1:20 PM 6/20/2018 54Explanation / Answer
Hello Student!
I am happy to help you!
************************* Code starts here ************************
#include <stdio.h>
int main(int argc, const char * argv[]) {
// insert code here...
printf("Enter the number of lines for the punishment: ");
int line ;
scanf("%d", &line);
if (line != (int)line) {
printf("You entered an incorrect value for the number of lines! ");
return 0;
}
printf("Enter the line for which you want the typo: ");
int typoLine;
scanf("%d", &typoLine);
if (typoLine != (int)typoLine) {
printf("You entered an incorrect value for the line typo! ");
return 0;
}
for (int i = 1 ; i <= line ; i++) {
if (i == typoLine) {
printf("C programming is the bet! ");
}else {
printf("C programming is the best! ");
}
}
printf(" ");
return 0;
}
************************* Code ends here ************************
Test Case Output :
Enter the number of lines for the punishment: 4
Enter the line for which you want the typo: 1
C programming is the bet! C programming is the best! C programming is the best! C programming is the best!
Program ended with exit code: 0
Enter the number of lines for the punishment: 6
Enter the line for which you want the typo: 3
C programming is the best! C programming is the best! C programming is the bet! C programming is the best! C programming is the best! C programming is the best!
Program ended with exit code: 0
Thank you. Feel free to ask anything. If you like the answer. Please upvote it. It means a lot. Thank you again.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.