Question

Design, code, and test a program that includes a function of type double called divbaby that...

Design, code, and test a program that includes a function of type double called divbaby that accepts two double arguments (you must write the divbaby function). When called, your function will return the first argument divided by the second argument. Make sure your function includes a decision statement so that it can't divide by 0--if the caller attempts to divide by 0 the function should return a value of -2.0. Your program should call divbaby then display the value returned by the function. Test your function thoroughly then submit output using the arguments 45.7 and 21.3. Remember that a structured function will have have only one return statement.

in a c program please.

Homework Answers

Answer #1

C code:

#include <stdio.h>
//initializing divbaby function
double divbaby(double num1,double num2){
//checking if the second number is 0
if(num2==0)
//returning -2.0
return -2.0;
else
//returning num1 divided by num2
return num1/num2;
}
int main()
{
//calling divbaby function and printing the result for sample value
printf("%lf",divbaby(45.7,21.3));
return 0;
}
Screenshot:


Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write in C++ program and write a function named computeCostPlusGST. It should accept two double type...
Write in C++ program and write a function named computeCostPlusGST. It should accept two double type variable as arguments. The first argument should be named cost; the second argument should be named rate. The argument rate should have a default value of 0.15. The function should return by value the value of cost plus the product of cost and rate
Write in C++ program and write a function named add. It should accept two const double...
Write in C++ program and write a function named add. It should accept two const double type references as arguments. The first argument should be named num1; the second argument should be named num2. The function should return by value of num1 plus num2.
Logic and Design Programming In Syntax Pseudocode Algorithm Workbench 1. Design a simple function named timesDozen...
Logic and Design Programming In Syntax Pseudocode Algorithm Workbench 1. Design a simple function named timesDozen that accepts an Integer argument into a parameter named nbr. When the function is called, it should return the value of its argument multiplied times 12. 2. Assume that a program has two String variables named alpha and bravo. Write - a pseudocode statement that assigns an all uppercase version of alpha to the bravo variable. Book name is Starting Out with Programming Logic...
My assignment is listed below. I already have the code complete, but I cannot figure out...
My assignment is listed below. I already have the code complete, but I cannot figure out how to complete this portion: You must create a makefile to compile and build your program. I can't figure out if I need to create a makefile, and if I do, what commands do I use for that? Create a  ContactInfo class that contains the following member variables: name age phoneNumber The ContactInfo class should have a default constructor that sets name = "", phoneNumber...
1) Develop a C++ function that determines the average value of an array of type double...
1) Develop a C++ function that determines the average value of an array of type double elements double GetAverage(double array[], int size) The function should accept as input an array of double values The function should accept as input the number of elements in the array of double values The function should return a double value which is the array's average value 2) Develop a C++ function that determines the variance of an array of type double elements double GetVariance(double...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter...
PROGRAM PYHTON Write a function called "calculateInput" that when called, it asks the user to enter an number. Then, it asks for a second number. These will use the "input" command. Store these as two separate variables. This function takes NO arguments and is also a VOID function, there is no return statement. The function should print the result of these two numbers multiplied together. The program should be able to multiply floats. For example: Test Input Result calculateInput() 5...
Define and test a function myRange. This function should behave like Python’s standard range function, with...
Define and test a function myRange. This function should behave like Python’s standard range function, with the required and optional arguments, but it should return a list. Do not use the range function in your implementation! Study Python’s help on range to determine the names, positions, and what to do with your function’s parameters. Use a default value of None for the two optional parameters. If these parameters both equal None, then the only provided argument should be considered the...
A. Write C code to create a structure called time_of_day, which stores the current time in...
A. Write C code to create a structure called time_of_day, which stores the current time in hours, minutes, and seconds. All the fields should be integers except for seconds, which should be a floating point value. B. Write a C function called check_time, which takes a pointer to a time_of_day structure as input, and return 1 if the time is valid (0 to 23 hours, 0 to 59 minutes, 0 to 59.999999 seconds) and 0 otherwise. Assume that times are...
solve in python 3.8 please The question is about Strings Modify your function so that it...
solve in python 3.8 please The question is about Strings Modify your function so that it can handle the following two situations: The string given as an argument has no characters. In this case, you should return the empty string. The string given as an argument has one character. In this case, you should return the one-character string given to you. Without any consideration for these cases, your function probably causes an error or returns the wrong result in the...
C++ only: Please implement a function that accepts a string parameter as well as two character...
C++ only: Please implement a function that accepts a string parameter as well as two character arguments and a boolean parameter. Your function should return the number of times it finds the character arguments inside the string parameter. When both of the passed character arguments are found in the string parameter, set the boolean argument to true. Otherwise, set that boolean argument to false. Return -1 if the string argument is the empty string. The declaration for this function will...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT