Question

hello I am working in a c++ problem and my answers should have decimals but when...

hello I am working in a c++ problem and my answers should have decimals but when I compiled run the program it does not show any decimals

Homework Answers

Answer #1
If you perform integer division then you get integer results only.
For example
int i = 5, j = 2;
then if you ptint
cout<<(i/j)<<endl;
Then it prints 2 instead of 2.5.

So, If you want result in decimal then just multiply expression with 1.0.
For example
cout<<(1.0*i/j)<<endl;
This prints in decimal value 2.5

Or you can also cast the result to float.
For example
cout<<((double)i/j)<<endl;
This also prints in decimal value 2.5

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
Hello I am working on my assignment for management class. I have calculated the total asset...
Hello I am working on my assignment for management class. I have calculated the total asset turnover ration for year 2015 and 2016 by using this formula. Total asset turnover ratio= total operating revenues/ total assets year 2016= 1378287738/1567838211= 0.87 year 2015= 1227830814/1384461557= 0.88 My question is how can i know the benchmark?
Hello I am currently working on an informative speech for my class. My topic that I...
Hello I am currently working on an informative speech for my class. My topic that I will be speaking on is the importance of budgeting. I am came up with this outline so far: Specific Purpose: To inform the audience about the importance of budgeting - advantages Central Idea: Making a budgeting plan is easy and the most critical step - great tool Introduction Question: what’s more important to you? A daily Starbucks drink or a yearly beach vacation. Why...
Constructing Direct Proofs so i am working with my hw and i get stuck. problem: if...
Constructing Direct Proofs so i am working with my hw and i get stuck. problem: if a is an integer, b is an odd integer, and c is an even integer, then a( b-c ) is an odd integer. I need a known show table and then a complete proof for this problem. for now i only set up hypothesis and definition of odd and even, and set it = to a(b-c) and not sure whats next~
Hello! I am coding in c# and I am having trouble using boolean variables and if...
Hello! I am coding in c# and I am having trouble using boolean variables and if statements. The project I am working on is based on the users input, and the code should branch into two different options. However, I am struggling to understand how to take the users input to decide which path to take. Another problem I am having is with my if statements. After the user has inputed information and the code decides to take them down...
Hello, This is for my Finance class. I am trying to find the monthly return of...
Hello, This is for my Finance class. I am trying to find the monthly return of some stocks. I have the Opening Price and the Closing price for each month. I have calculated the monthly return using this formula: (Closing Price - Starting Price) / Starting Price Is this the accurate formula? Here is the data and my answers for the first few months. Are they correct? Opening Closing Return 56.30 60.71 .0783 60.95 55.98 -.0815 55.92 55.57 -.0063 55.65...
I am working on my semester project for fundamentals on web design. I am stuck on...
I am working on my semester project for fundamentals on web design. I am stuck on the question. It says I need to use the drawing features of word processing program, a graphic application, or a paper and pencil to create a site map for your website that shows the hierarchy of pages and reltionships between the pages. So I am kinda of confused how to do to that
Hello, I have a finance question I am confused on. A stock just paid a dividend...
Hello, I have a finance question I am confused on. A stock just paid a dividend of $2.71. The dividend is expected to grow at 28.38% for five years and then grow at 4.69% thereafter. The required return on the stock is 13.76%. What is the value of the stock? (Round to 2 decimals) It says the correct answer is $77.01 but I am having trouble trying to reach it. Any help would be greatly appreciated!
UNITY QUESTION I am working with my team in Unity to create a character. I am...
UNITY QUESTION I am working with my team in Unity to create a character. I am responsible for creating a character's moves. Nothing really has been done yet, but could you provide an example of code using C# or C++ or even pseudocode Please provide functions for my character to go walk, run, move up, move down, move forward, and move backwards. I will give a thumbs up if it is decent :) Just give me an example code for...
Hello- I am working on SPSS analysis and am still struggling to understand how to use...
Hello- I am working on SPSS analysis and am still struggling to understand how to use kurtosis to describe a sample. If I have one sample with a kurtosis score of -0.041 and another with a kurtosis score of -1.16, how can I best describe these samples (i.e. are they normal, near normal, abnormal, etc)? Thank you!
Hello I have a question with my Cost Accounting Class. I am not sure about the...
Hello I have a question with my Cost Accounting Class. I am not sure about the math of how to figure out the answers. If anyone could show me how to get the answers with the math that would be wonderful. Thank you Shell Cool Company applies manufacturing overhead on the basis of machine-hours. On December 31, the company’s manufacturing overhead control T-account included the following amounts for the whole year. Manufacturing Overhead Control 4,788,841 5,152,000 At the beginning of...