i was making a program to have a user enter a radius, a integer of radius growth and a ending radius into a program, then comparing the volume differences in all the radius' of the spheres that were made, but i ave run into a snag, the while loop i was going to use dosent want to work for my purposes, and i am getting tired of this program altogether, could some1 just give me th next step of the problems i wil run into. I'm not asking for a full code of the solution, but that could always help
****** and no this is not some dumbass high school kid asking people to do his homework*********
#include <iostream>
#include <math.h>
usingnamespace std;
/* volume calculation*/
int main()
{
double radini, old, current, radc, radend, vol, vol2, voldiff;
cout<<"Enter the initial radius of the sphere: ";
cin>>radini;
cout << "Enter the incremental value of the radius: ";
cin >> radc;
cout << "enter the ending value of the radius: ";
cin >> radend;
vol = (4.0 / 3.0) * (3.14) * (pow(radini, 3.0));
cout<<" The radius initialy is "<<radini;
cout << "\n\n";
current = radini;
cout << " The volume with a radius of " << current;
cout << " is " << vol;
old = radini;
while (current < radend)
{
current = radini + radc;
voldiff = vol-vol2;
vol2 = (4.0 / 3.0)* (3.14) * (pow(old, 3.0));
vol = (4.0 / 3.0) * (3.14) * (pow(current, 3.0));
voldiff = vol - vol2;
cout << current << "\n the current radius is ";
cout << vol << "\n the current volume is ";
cout << vol2 << "\n the old radius is ";
cout << "\n so the difference is " << voldiff;
}
}
You never change the value of current. Line 27 should instead be current = current + radc;. Don't forget to set current to radini before the loop though or it will contain garbage.
Also, set old = current; right before changing current.
#include <iostream>
#include <math.h>
usingnamespace std;
/* volume calculation*/
int main()
{
double radini, old, current, radc, radend, vol, vol2, voldiff;
cout<<"Enter the initial radius of the sphere: ";
cin>>radini;
cout << "Enter the incremental value of the radius: ";
cin >> radc;
cout << "enter the ending value of the radius: ";
cin >> radend;
vol = (4.0 / 3.0) * (3.14) * (pow(radini, 3.0));
cout<<" The radius initialy is "<<radini;
cout << "\n\n";
current = radini;
cout << " The volume with a radius of " << current;
cout << " is " << vol;
old = radini;
while (current <= radend)
{
vol2 = (4.0 / 3.0)* (3.14) * (pow(old, 3.0));
old = current;
vol = (4.0 / 3.0) * (3.14) * (pow(current, 3.0));
voldiff = vol - vol2;
cout << "\n the current radius is " << current;
cout << "\n the current volume is " << vol;
cout << "\n the old volume is " << vol2;
cout << "\n so the difference is " << voldiff;
current = current + radc;
}
}