Help with intro to c HW Identify and correct the errors, if there are any, in th
ID: 3678667 • Letter: H
Question
Help with intro to c HW
Identify and correct the errors, if there are any, in the following program segments. Briefly explain why. Calculate the value of the following function using a C function at.x = 3.5. g-1(x) = 2xsin(x) + cos(x) + Write a C program that uses the function rand() to generate an integer randomly in the range of 1 to 50. The random number generated by the program shall be different at each run. The program then prompts the user to guess the number by displaying the following messages: I have a number between 1-50. Can you guess what it is? Enter your initial guess. After the user's initial guess, the program should display one of the following responses: Correct! That's the number. Would you like to play again (y or n)? Too low. Guess again. Too high. Guess again. The program should loop until the user guesses the correct answer. Use the "Too low" and "Too high" messages to help the user guess the number. Once the user guesses the right number, the program should ask whether he/she would like to play again. Describe your algorithm in procedures, pseudocode, and flowchart. (Note: write a function called guessGame () to play this "guessing game".)Explanation / Answer
a)
Error!!! prototype shows double type parameter, while actual function uses int parameter
b)
Error!!! actual function has one parameter, while the function call has 2
c)
Error!!! prototype consists of void return type, while fuction definition consists of int
d)
Error!!! function definition has void return type, but function returns int value
e)
Error!!! variable name sum and function name sum() are same
6.
double fun(double x)
{
double r = 2*x*sin(x)+cos(x)+((4*x+3)/(3*x*x+2*x+1));
return r;
}
7.
#include<stdio.h>
#include<stdlib.h>
void main()
{
int r,ans;
r=rand()%50+1;
printf("I have a number between 1-50");
printf(" can you guess what it is?");
while(true)
{
printf(" Enter your initial guess");
scanf("%d",&ans);
if(ans==r)
{
printf("Correct! Thats the number");
break;
}
else if(ans<r)
printf("Too low. Guess again");
else
printf("Too high. Guess again");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.