#include <iostream>

#include <cstdlib>using namespace std;

int main()

{

int numpart;

int UX;

int UY;

int UZ;

int factor;

cout << "How many particles are in one unit cube of your lattice?" << endl;

cin >> numpart;

cout << "What is the unit length (x) of your box?"<< endl;

cin >> UX;

cout << "What is the unit length (y) of your box?"<< endl;

cin >> UY;

cout << "What is the unit length (z) of your box?"<< endl;

cin >> UZ;

cout << "What is the multiplication factor to create this lattice?" << endl;

cin >> factor;

cout << "You are creating a lattice that contains "<< (UX * factor * UY * factor * UZ * factor * numpart)<< " particles"<< endl;

cout << "You are creating a lattice whose volume is " << (UX * factor * UY * factor * UZ * factor) << " volume units" << endl;

for (int x=0; x < factor;(x + UX))

{cout << "i am awesome" << endl;}

return 0;

}

I am so sorry I don't know how to put it in the "code" page...But I hope this shows up cleanly on the question page.Nevermind the y and z values, I'm getting "i am awesome" in infinite loops! Why is this happening? Is it because the conditions inside the for () bracket doesn't recognize UX? How can I fix this problem?

Thanks!

Its ben sumtime since iv done this but you need to conecntrat on this bit of code. for (int x=0; x < factor;(x + UX))

if you can explain what it is you want it to do it would help me understand how to solve. it seems to be the loop that is the problem you have set the int to 0 but i cant see what number in the counter you have set it to stop at. if there is not a number for it to reach and stop then it will continue in an infinite loop.

But i you can provide more information that might help as its been about 1 year since iv even look at code after finishing college.

Regards

Daniel

Hi Daniel! yay! thanks for replying.

Yeah, I just realized that that's the problematic part of the code.if you look up to where I'm declaring variables, I'm letting the user input what is UX and factor. I want to be able to use this within the condition of the for loop, but it ends up giving me an infinite loop of the output as i've written "i'm awesome"

How can I make sure that the computer knows that I want it to utilize user input values of UX and factor when i'm declaring conditions of the "for loop"?

Erm wel im trying to think back. i think i understand what you cant which is sumthing we had to do where the user in put data an the the program showed the data back to the user. im nt sure u need a loop just

cout <<" I CANT REMEMBER WHAT TO PUT HERE TO CALL THE USER INPUT. "<< endl;Sorry i cant be more help. but it has been a while since iv done coding and dont have any of my old work with me at the moment.

I also have forgotten a lot. Try this.

....................................................................................................................

for (int x=0; x < factor;(x = x + UX))

...................................................................................................................._Adnan_

nope, still gives me the infinite loop of doom... ): i figured out everything else but this. i'll ask my grad student advisor when she comes to school today...

thanks for your help though guys (:

for (int x=0; x < factor;x += UX)

This should break you out of the loop, assuming UX is > 0.

This is what I came up with. This works, but I have tried all the options above and it still gives me the infinite loop of doom. What I changed: UX/UY/UZ are now the same thing as x,y, and z.

factors is now f

numbpart is now numb#include <iostream>

#include <cstdlib>using namespace std;

int main()

{

int numb;

int f;

double x;

double y;

double z;

cout << "How many particles are in one unit cube of your lattice?" << endl;

cin >> numb;

cout << "What is the unit length (x) of your box?"<< endl;

cin >> x;

cout << "What is the unit length (y) of your box?"<< endl;

cin >> y;

cout << "What is the unit length (z) of your box?"<< endl;

cin >> z;

cout << "What is the multiplication factor to create this lattice?" << endl;

cin >> f;

cout << "You are creating a lattice that contains "<< (x * f * y * f * z * f * numb)<< " particles"<< endl;

cout << "You are creating a lattice whose volume is " << (x * f * y * f * z * f) << " volume units" << endl;for (x=0; x <3 ; x++ )

{for (y=0; y < 3; y++)

{for (z=0; z < 3; z++)

{cout<<"("<<x<<", "<<y<<", "<<z<< ")\n"<< endl;}

}

}for (x=0.5; x < 3 ; x++ )

{for (y=0; y < 3; y++)

{for (z=0.5; z < 3; z++)

{cout<<"("<<x<<", "<<y<<", "<<z<< ")\n"<< endl;}

}

}for (x=0; x < 3 ; x++ )

{for (y=0.5; y < 3; y++)

{for (z=0.5; z < 3; z++)

{cout<<"("<<x<<", "<<y<<", "<<z<< ")\n"<< endl;}

}

}

for (x=0.5; x < 3 ; x++ )

{for (y=0.5; y < 3; y++)

{for (z=0; z < 3; z++)

{cout<<"("<<x<<", "<<y<<", "<<z<< ")\n"<< endl;}

}

}return 0;

}I would really like to be flexible with this file, I don't want to have to change up the numbers in the .cpp file-- otherwise there's no point in asking for user input in the first place!

Thanks,

Wait, in the original post, you're using ints. In this version, you're usingdoubles. This might be your problem.

I used doubles because I had to use four separate "for loops" and the initial values for x,y,and z are sometimes numbers with decimals. that could potentially be a problem though i'll check it out, thanks

Ask Your Question

Weekly Poll

Do you think Microsoft can save the Surface Book lineup?

Discuss in The Lounge

Poll History