### [Request] Help on a do/while loop

I'm trying to make a program that will allow a user to decide whether or not to repeat the program at the end. My program asks for user input, and based on what planet they pick, data values will be added to the associated data file. I want the user to be able to choose whether they get prompted to enter another planet, or to end the program. I'm having trouble with my do/while loop to achieve this.

My code:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293`` ``````#include #include #include #include #include #define PEarth 8.964 #define PMars 2.421 #define PMercury .269 #define PVenus 15.913 #define eEarth .0167 #define eMars .0934 #define eMercury .206 #define eVenus .00677 #define pi 3.1416 using namespace std; int main() { double A1, A2, Ai, e, r, x, y, theta,c; string P; do { cout<<"Starting value of angle: "; cin>>A1; cout<<"Ending value of angle: "; cin>>A2; cout<<"Increment of angle: "; cin>>Ai; cout<<"Choose one planet (Earth, Mars, Mercury, or Venus): "; cin>>P; ofstream outfile; if(P=="Earth" || P=="earth") { outfile.open("earth.dat"); for(theta=A1; theta<=A2; theta+=Ai) { r = (PEarth*eEarth)/(1-eEarth*cos((A2-A1)*(pi/180))); x = r*cos(theta); y = r*sin(theta); outfile<>c; } if(P=="Mercury" || P=="mercury") { outfile.open("mercury.dat"); for (theta=A1; theta<=A2; theta+=Ai) { r=(PMercury*eMercury)/(1-eMercury*cos((A2-A1)*(pi/180))); x=r*cos(theta); y=r*sin(theta); outfile<>c; } if(P=="Venus" || P=="venus") { outfile.open("venus.dat"); for (theta=A1; theta<=A2; theta+=Ai) { r=(PVenus*eVenus)/(1-eVenus*cos((A2-A1)*(pi/180))); x=r*cos(theta); y=r*sin(theta); outfile<>c; } } while(c=='y'||c=='Y'); system ("pause"); return 0; }``````
Last edited on
You declare c as a double and then try to use it as a character. Declare it correctly and it should be fine.

Also, you shouldn't have the "Do you want to continue?" part at the end of each if statement; instead put it after all of them, right before the loop ends. No need to repeat the code.
Thank you very much! I knew it was something simple.
Topic archived. No new replies allowed.