Well...
A for loop looks like this (or better said; it can look like this)
Code:
for(int i = 0; i < 10; i ++)
{
cout << "Value of integer variable i: " << i;
}
If you want to do a thing, at least once, you should use a do-while loop, looks like this:
Code:
int i = 0
do
{ //This is ran at least one time no matter what the "while statement" below returns
cout << "ManyTimes is such a handsome guy";
i++;
}
while(i < 10);
Here is a main you might like:
Code:
int main()
{
double load,length,loadb,width(6),test,loadc,result;
ofstream outfile; //declare var to write to file
outfile.open("hw4c.txt");//open output file to write to
char c;
do
{
cout<<"Enter the expected load in pounds: ";
cin>>load;
cout<<"Enter the length of the column in inches: ";
cin>>length;
{
loadb=buck(length,width);
loadc=comp(width);
result=slender(length,width);
}
cout<<loadb<<"\n";
cout<<loadc<<"\n";
cout<<result<<"\n";
if (load<=loadb && load<=loadc && result==1)
{
//test=0;
cout<<"For a load of "<<load<<" and a length of "<<length<<" inches, recommended sqaure beam has a side of "<<width<<" inches\n";
}
else
test=1;
cout<<test<<"\n";
cout << "Want to quit or go again? (q = quit, anything else continue";
cin >> c;
}while(c != 'q'); //programme runs as long as "c" is not "q" (little q)
system("pause");
return 0;
}
With that code in the "int main()" function, your program will run over and over again, as long as the user doesnt write "q" at the end when he is asked for quit or continue...
PS: I think Ive misunderstood your question, you dont want Main to loop?
hmm...
//for(width=2;test=1;width=width+2)
What are you trying to loop? How many times should the loop go? What?