Question

In: Computer Science

Below is the C ++ code for a given assignment. An acre equal 43,560 sq ft....

Below is the C ++ code for a given assignment. An acre equal 43,560 sq ft. Im supposed to find the total number of acres within a tract of land that is 391,876 sq ft. the program compiles and runs just fine but I'm wondering if it would be better to use the int data type instead? I used double for more accuracy. The instructor didn't say we had to use any certain data type so I'm asking purely for practicality and for real world scenarios which would be better.

// this program calculates the number of acres in a tract of land
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
   double acre = 43560,
           land = 391876,
           total;
         
  
   //Calculate the total number of acres
  
   total = land / acre;
  
   cout<<"the total number of acres is " << total << endl;
   return 0;

Solutions

Expert Solution

What you did is exactly right !!!!!!!!!!!!

In practical, we should use double value only.

WHEN SHOULD WE USE INT??

We use int datatype only when we don't get any fractional part in the answer.

Example: Multiplication of two integers will always give an int value only. We never get a fraction.

2*3=6

4*5=20

10*0=0

and so on

ALL are int values, so we can use int for integer multiplication.

WHEN SHOULD WE USE DOUBLE??

we will use double datatype if we know that any fraction may come up in the solution.

Example: DIVISION can always give you a fraction.

3/2=1.5

4/2=2 (we can also take 2.0, a double value)

5/2=2.5

3/4=0.75

and so on

=================================================

In your case, you have got the answer as 8.99624

======

So, you use double.

You can also use float if you want precision upto only 6 digits.


Related Solutions

Potential Gross Income 100,000 sq. ft for the coming year average rent $15.00 per ft. $  ...
Potential Gross Income 100,000 sq. ft for the coming year average rent $15.00 per ft. $   1,500,000 Less Vacancy Allowance (average 8%) $     (120,000) Effective Gross Income $   1,380,000 Cleaning expenses (5% of net rev) $      (69,000) Insurance ($ 0.02 per dollar replacement, R.C. = $40 per ft. $      (80,000) Management & Maintenance (11% of revenue) $    (151,800) Reserve for Replacement (savings for major repairs) $      (50,000) Property Taxes ($0.10 per $100 of R.C.) $          (4,000) $    (354,800) Estimated Net...
Potential Gross Income 100,000 sq. ft for the coming year average rent $15.00 per ft. $  ...
Potential Gross Income 100,000 sq. ft for the coming year average rent $15.00 per ft. $   1,500,000 Less Vacancy Allowance (average 8%) $     (120,000) Effective Gross Income $   1,380,000 Cleaning expenses (5% of net rev) $      (69,000) Insurance ($ 0.02 per dollar replacement, R.C. = $40 per ft. $      (80,000) Management & Maintenance (11% of revenue) $    (151,800) Reserve for Replacement (savings for major repairs) $      (50,000) Property Taxes ($0.10 per $100 of R.C.) $          (4,000) $    (354,800) Estimated Net...
Consider a 100,000 sq. ft. building that will be acquired (at price $0) and demolished by...
Consider a 100,000 sq. ft. building that will be acquired (at price $0) and demolished by local government at the end of 15 years.  Assume the building is fully leased building under an absolute net lease structure (all expenses paid by tenant); Consider 2 leases:       15 year lease at $15/ft./yr.       5 year lease at $15/ft./yr. Suppose that $15 is the market rate and that the forecasted rent growth rate is 0% . Also suppose that the discount rate for contractual lease...
Price (thousands of $) Size (sq. ft.) # of Bedrooms # of Baths Distance to Town...
Price (thousands of $) Size (sq. ft.) # of Bedrooms # of Baths Distance to Town Center Garage Dummy (1=garage; 0=no garage) Pool Dummy (1=pool; 0=no pool) 271.8 2100 2 2.5 9 1 0 221.1 2300 3 1.5 18 0 1 266.6 2400 4 2 13 1 0 292.4 2100 4 2 14 1 0 209 1700 2 1.5 8 1 0 270.8 2500 6 2 7 1 0 246.1 2100 4 2 18 1 0 194.4 2300 2 2...
Need this in C#. Below is my code for Problem 3 of Assignment 2. Just have...
Need this in C#. Below is my code for Problem 3 of Assignment 2. Just have to add the below requirement of calculating the expected winning probability of VCU. Revisit the program you developed for Problem 3 of Assignment 2. Now your program must calculate the expected winning probability of VCU through simulation. Run the simulation 10,000 times (i.e., play the games 10,000 times) and count the number of wins by VCU. And then, calculate the winning probability by using...
Your company is using a plant of size 10,000 sq. ft. that was constructed in 2006...
Your company is using a plant of size 10,000 sq. ft. that was constructed in 2006 for $300,000. The cost indices that correspond to this size of a plant for 2006 and 2014 are 145 and 186 respectively. If the power-sizing exponent is 0.55, how much would it cost to build a 40,000 sq. ft. warehouse in 2014? Note: Answer would be $816,026. Please include complete explanation and step-by-step solution.
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI....
I need the c# code for the below assignment. Complete PigLatin program in Windows Forms GUI. Zip the solution project file and attach to this submission. Do this in the GUI format (Windows Form). Be sure and add a Clear Button to reset for entering another word or words. PigLatinGUI Basic Steps in Creating your Program Create your user interface (GUI). Use different font styles but don’t overdo it, Use colors, and Use graphics (You can find all kinds of...
Consider the following pro forma for the next 4questionsPotential Gross Income 100,000 sq. ft...
Consider the following pro forma for the next 4 questions Potential Gross Income 100,000 sq. ft for the coming year average rent $15.00 per ft. $   1,500,000 Less Vacancy Allowance (average 8%) $     (120,000) Effective Gross Income $   1,380,000 Cleaning expenses (5% of net rev) $      (69,000) Insurance ($ 0.02 per dollar replacement, R.C. = $40 per ft. $      (80,000) Management & Maintenance (11% of revenue) $    (151,800) Reserve for Replacement (savings for major repairs) $      (50,000) Property Taxes ($0.10...
Average area covered by a can of 1-gallon paint is 513.3 sq ft with a variance...
Average area covered by a can of 1-gallon paint is 513.3 sq ft with a variance of 992.25 sq ft. Ascertain the probability that the mean area covered by a sample of 40 of these 1-gallon cans will be between 510 to 520 sq ft?
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies...
Assignment Content Resource: ****************************CODE PASTED BELOW******************************* For this assignment, you will develop Java™ code that relies on localization to format currencies and dates. In NetBeans, copy the linked code to a file named "Startercode.java". Read through the code carefully and replace all occurrences of "___?___" with Java™ code. Note: Refer to "Working with Dates and Times" in Ch. 5, "Dates, Strings, and Localization," in OCP: Oracle® Certified Professional Java® SE 8 Programmer II Study Guide for help. Run and debug...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT