Question

If the result is an integer value write the integer without commas or decimals If the...

  • If the result is an integer value write the integer without commas or decimals
  • If the result is a double value write the decimal to exactly 2 decimal places
  • If the operation is division or module and the denominator is zero, write: Invalid
  • If the operation is division or modulo and the denominator is a negative value, write: Varies
  • If the operation is module and the numerator is a negative value, write: Varies

#define IVAR 100
double x, y;
int a, b, i;
a = 9;
b = 4;
y = 5.0;

x = b / a;

Homework Answers

Answer #1

double x, y;
int a, b, i;
a = 9;
b = 4;
y = 5.0;

x = b / a;

The value of x after executing this code will be 0

This is because, both b and a are integers, so b/a yields integer division by default. Even though x is a double variable, the integer division of b/a returns 0 instead of 0.44. If you want to do this correctly, you will need to cast the result of b/a into double. That is changing x=b/a; into x=(double)b/a; in that case, the value of x will be 0.4444

Let me know if you have any doubts or if you need anything to change. If you are satisfied with the solution, please rate the answer. Thanks

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
Part II - Pi Calculation implementation. If you watch the Discovery or Sci-Fi channel you will...
Part II - Pi Calculation implementation. If you watch the Discovery or Sci-Fi channel you will find dozens of alien conspiracy shows that reference Pi as something so advanced that it must be alien.  The number πis a mathematical constant, the ratio of a circle's circumference to its diameter, commonly approximated as 3.14159. So you could graph the value or calculate an approximate value using the series given below: Pi = 4 * (1/1 – 1/3 + 1/5 – 1/7 +...
For this assignment you will implement a simple calculator or interpreter that reads arithmetic expressions from...
For this assignment you will implement a simple calculator or interpreter that reads arithmetic expressions from a file. Specifically, you will implement the following function: /* * Reads one arithmetic "expression" at a time from a file stream, computes, then * returns the result. If there are additional expressions in the file, they are * read and computed by successive calls to “calculator”. * * “Expressions” are groups of operations (add, subtract, multiply, divide). Your * calculator will read and...
**C++** a. Write a program containing the following expressions. x should be an int variable. Add...
**C++** a. Write a program containing the following expressions. x should be an int variable. Add a statement after each one to print out the current value of x in the following format (of course, you will print the value of x, not the constant 4!): Problem 1. x has the value 4 1. x = 4; 2. x = 2; 3. x = 24 – 6 * 2; (show each computation) 4. x = -15 * 2 + 3;...
This is C programming assignment. The objective of this homework is to give you practice using...
This is C programming assignment. The objective of this homework is to give you practice using make files to compose an executable file from a set of source files and adding additional functions to an existing set of code. This assignment will give you an appreciation for the ease with which well designed software can be extended. For this assignment, you will use both the static and dynamic assignment versions of the matrix software. Using each version, do the following:...
Write a program that accepts as input the mass, in grams, and density, in grams per...
Write a program that accepts as input the mass, in grams, and density, in grams per cubic centimeters, and outputs the volume of the object using the formula: volume = mass / density. Format your output to two decimal places. ** Add Comments ** Print Name and Assignment on screen ** Date ** Submit .cpp file. Demo // This program uses a type cast to avoid an integer division. #include <iostream> // input - output stream #include <fstream> //working file...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159;...
#include<iostream> #include<iomanip> using namespace std; int main() { //variables int choice; float radius,base,height,area; const double PI=3.14159; //repeat until user wants to quits while(true) { //menu cout<<endl<<endl<<"Geometry Calculator"<<endl<<endl; cout<<"1. Calculate the area of a circle"<<endl; cout<<"2. Calculate the area of a triangle"<<endl; cout<<"3. Quit"<<endl<<endl; //prompt for choice cout<<"Enter your choice(1-3): "; cin>>choice; cout<<endl; //if choice is circle if(choice==1) { cout<<"What is the radius of the circle? "; cin>>radius; //calculating area area=PI*radius*radius; cout<<endl<<"The area of the circle is "<<fixed<<setprecision(3)<<area<<endl; } //if choice...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following...
1. Vim commands: a. How do you auto indent your program? b. Explain what the following commands do: dd, y3, p, :set cindent (1 pt) VIM exercises These exercises on the computer need to be repeated by each student in the pair. This is to ensure that both students understand how to get around in Linux!!! For this part of the lab, you will create a .vimrc file that will help you develop your C++ programs using VIM. First, we...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class...
0. Introduction. In this laboratory assignment, you will write a Python class called Zillion. The class Zillion implements a decimal counter that allows numbers with an effectively infinite number of digits. Of course the number of digits isn’t really infinite, since it is bounded by the amount of memory in your computer, but it can be very large. 1. Examples. Here are some examples of how your class Zillion must work. I’ll first create an instance of Zillion. The string...
6. The data show the time intervals after an eruption​ (to the next​ eruption) of a...
6. The data show the time intervals after an eruption​ (to the next​ eruption) of a certain geyser. Find the regression​ equation, letting the first variable be the independent​ (x) variable. Find the best predicted time of the interval after an eruption given that the current eruption has a height of 149 feet. Height​ (ft) 108 124 108 152 109 138 137 103 Interval after​ (min) 77 73 81 87 69 91 90 68 What is the regression​ equation? ​...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • describe the three fiscal policy tools at the government's disposal to stimulate or contract the economy....
    asked 12 minutes ago
  • i) Write the condensed electron configurations for the following ions: (a) Ca+ (b) S2- (c) V2+...
    asked 12 minutes ago
  • In Java a function can call itself(we may explore more about this later in the course).  This...
    asked 25 minutes ago
  • Write a short program,Java, that implements the Caesar substitution cipher with k=3. That is, each letter...
    asked 27 minutes ago
  • Design a function named findMax that accepts two integer values as arguments and returns the value...
    asked 33 minutes ago
  • In MIPS, I am trying to create an array of 7 words that can either be...
    asked 34 minutes ago
  • Cash, $2,000 Accounts Receivable, $1,250 Professional Equipment, $10,200 Office Equipment, $5,500 Accounts Payable, $3,500 P. Palmer,...
    asked 35 minutes ago
  • Add two more statements to main() to test inputs 3 and -1. Use print statements similar...
    asked 36 minutes ago
  • C++ program called that reads a string and check if it’s well-formed or not. ex== The...
    asked 47 minutes ago
  • 1: Describe five functions of nonverbal communication. (Creating and maintaining relationships, Regulating Interaction, Influencing others, Concealing/deceiving,...
    asked 1 hour ago
  • Trucks that travel on highways have to stop at various locations to be weighed and inspected...
    asked 1 hour ago
  • Define and describe the PERT technique. For the toolbar, press ALT+F10 (PC) or ALT+FN+F10 (Mac).
    asked 1 hour ago