I am trying to write a code for a project and I am trying to make a while loop but it keeps repeating when I run it. I am also trying to get it to make a table but it wont show up either. Here is what I have so far.
Here is also the steps to see what I am trying to go for:
https://i.stack.imgur.com/6jFPR.png
#include<iostream> //Required for cout
#include <cmath>
using namespace std;
const double h=1.3;
const double k= 0.3;
const double pi = 3.141593;
int main()
{
// Declare and initialize objects.
int time(0);
double t, SurfaceArea, Volume, Radius,InitialRadius , IR, R;
cout << "Hello user! please put in the Initial Radius ";
cin >> IR;
InitialRadius = IR;
cout << "Now please put in the time:";
cin >> t;
while (time <= 5.4)
{
cout<<"Time(sec) Radius (m) Surface area (m2) Volume (m3)";
cout << time << " " << Radius << " " << SurfaceArea << " " <<
Volume << endl;
Radius = k * InitialRadius*t;
SurfaceArea = pi*(pow(Radius*pow(t, 2)+pow(h,2),0.5));
Volume = 0.33 * pi*pow(Radius,2)*h;
time += 10;
}// end loop
// Exit program.
return 0;
} //end main
2
Answers
Things that are wrong (my machine refuses to compile it)
Fix those things for a start
It appears that ‘t’ in your while loop never changes once it enters the loop. This will cause a infinite loop unless ‘t’ is updated inside the loop. If ‘t’ is supposed to change by +0.19, do
I believe IR is supposed to be InitialRadius, but it is not initialized to such. Do this after you input IR:
R is not set to anything. If R is supposed to be Radius, make sure you set it as such:
Are you trying to print out Time, Radius, Surface area, and Volume in table format? And are they supposed to be printed out each time the loop runs through? If so, you need to cout these as well.
This will look something like: