Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Why does my code output in scientific notation program CalculateVolumes; #include ( stdlib . hhf ) ; static r: real 3 2 ;

Why does my code output in scientific notation
program CalculateVolumes;
#include("stdlib.hhf");
static
r: real32;
h: real32;
sphereVolume: real32;
cylinderVolume: real32;
coneVolume: real32;
pi: real32 :=3.1415927; // More accurate pi constant
begin CalculateVolumes;
stdout.put("Calculating volumes of Sphere, Cylinder, and Cone", nl);
// Collecting user input
stdout.put("What's your value of r: ");
stdin.get(r);
stdout.put("What's your value of h: ");
stdin.get(h);
// Calculate volume of a sphere
fld(r); // Load radius
fld(st0); // Duplicate radius (r)
fld(st0); // Duplicate radius (r)
fmulp(st0, st1); // r^2
fmulp(st0, st1); // r^3
fld(pi); // Load pi
fmulp(st0, st1); // pi*r^3
fld1;
fld1;
fld1;
faddp(st0, st1);
faddp(st0, st1); //3.0
fdivp(); //(pi*r^3)/3
fld1;
fld1;
fld1;
fld1; // Load 4.0
fadd(st0, st1);
fadd(st0, st1); // Make it 4.0 on stack
fmulp(st0, st1); //(4/3)*pi*r^3
fstp(sphereVolume); // Store the result in sphereVolume
// Calculate volume of a cylinder
fld(pi); // Load pi
fld(r); // Load radius
fld(st0); // Duplicate radius (r)
fmulp(st0, st1); // r^2
fld(h); // Load height
fmulp(st0, st1); // r^2* h
fstp(cylinderVolume); // Store the result in cylinderVolume
// Calculate volume of a cone
fld(cylinderVolume); // Load volume of cylinder
fld1;
fld1;
fld1; // Load 3.0
fadd(st0, st1);
fadd(st0, st1); // Make it 3.0 on stack
fdivp(); //(cylinderVolume)/3
fstp(coneVolume); // Store the result in coneVolume
// Output results
stdout.put("Your sphere has volume =", sphereVolume, nl);
stdout.put("Your cylinder has volume =", cylinderVolume, nl);
stdout.put("Your cone has volume =", coneVolume, nl);
end CalculateVolumes;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database 101

Authors: Guy Kawasaki

1st Edition

0938151525, 978-0938151524

More Books

Students also viewed these Databases questions

Question

2. Identify conflict triggers in yourself and others

Answered: 1 week ago