# Beginner question on a 'While'

• 09-22-2004
kev_inflames
Beginner question on a 'While'
Hey there people. Im sure its a silly mistake but i cant get my while to work.

sorry to dump a large code in your faces :rolleyes:

tell me off if you need to :)

Code:

```#include <iostream.h> float FindVolume(int diameter,int length)           {                     float pi = 3.14159265358979323846;                     float circumference = pi*diameter;                     float volume = circumference*length;                     return volume;           } int SquareThisNumber(int number)           {                     int SquaredNumber = number*number;                     return SquaredNumber;           } int main()           {                     int diameter;                     int length;                     int number;                     int choice;                     int exit = 0;       while(exit==0);  //Should loop because exit is specified as 0 above.                       //exit can only be changed by user input at end of program.             {           std::cout << "Choose what you want to do from the list below and enter the number" << std::endl;           std::cout << "1)Square a Number" << std::endl;           std::cout << "2)Find the Diameter of a Cylinder" << std::endl;           std::cin >> choice;           if(choice==1)                     {                         std::cout << "Please enter a number. I would love to square it." << std::endl;                         std::cin >> number;                         std::cout << number << " squared is: " << SquareThisNumber(number) << std::endl;                     }           else if(choice==2)                     {                         std::cout << "Type the diameter of a cylinder" << std::endl;                         std::cin >> diameter;                         std::cout << "Type the length of a cylinder" << std::endl;                         std::cin >> length;                         std::cout << "Diameter: " << diameter << "cm" << std::endl;                         std::cout << "Length: " << length << "cm" << std::endl;                         std::cout << "The volume is " << FindVolume(diameter,length) << "cm3" << std::endl;                     }           else                     {                         std::cout << "WTF! enter a number from the list above! foolish...";                     }           std::cout << "What would you like to do?" << std::endl;           std::cout << "0)Back to menu" << std::endl;           std::cout << "1)Exit Program" << std::endl;           std::cin >> exit;             }   return 0; }```

Thanks for taking the time to click my post :D
• 09-22-2004
dayknight
look harder at your "While" statement
• 09-22-2004
PJYelton
Code:

`while(exit==0); // Notice the semicolon?  Infinite loop!`
Don't worry, its happend to all of us!
• 09-22-2004
Vicious
Also,

I suggest you use standard headers.
For a simple fix
Code:

`#include <iostream>`
Code:

`#include <iostream.h>`
You are already doing std:: so you dont need using namespace std.
• 09-22-2004
kev_inflames
ah ha took the ; off and it worked silly me :s

thanks for the help guys :)
• 09-22-2004
JarJarBinks
```if(blah != 1 && blah != 2) {     return 0; } EX. if(choice==1) {       std::cout << "Please enter a number. I would love to square it." << std::endl;       std::cin >> number;       std::cout << number << " squared is: " << SquareThisNumber(number) << std::endl; } if(choice==2) {       std::cout << "Type the diameter of a cylinder" << std::endl;       std::cin >> diameter;       std::cout << "Type the length of a cylinder" << std::endl;       std::cin >> length;       std::cout << "Diameter: " << diameter << "cm" << std::endl;       std::cout << "Length: " << length << "cm" << std::endl;       std::cout << "The volume is " << FindVolume (diameter,length) << "cm3" << std::endl; } if(choice != 1 && choice != 2) {       std::cout << "WTF! enter a number from the list above! foolish..."; }```