0

#include<iostream.h>
#include<math.h>

void main()

{

float x,y;
cout<<"Please enter one number ";
cin>>x;
y=x*x;
cout<<"The square of the number you enter is "<<y<<endl;

}

:eek: Pls help... thx u very much...

3
Contributors
2
Replies
3
Views
13 Years
Discussion Span
Last Post by freesoft_2000
0

Use a loop.

#include <iostream>
  using std::cout;
  using std::cin;
  using std::endl;
  
  int main()
  {
     for ( ;/* your condition here*/; )
     {
  	  float x,y;
  	  cout << "Please enter one number ";
  	  cin  >> x;
  	  y = x * x;
  	  cout << "The square of the number you enter is " << y << endl;
     }
     return 0;
  }
0

hello everyone
try this

#include<iostream.h>
#include<math.h>


void main()


{


float x,y;


while(1)
{
cout<<"Please enter one number ";
cin>>x;
y=x*x;
cout<<"The square of the number you enter is "<<y<<endl;
if (x < 0)
{
break;
}
}
}

This loop goes on forever until the user inputs a negative number and then the loop is broken and the program ends unlike the for loop which has a fixed number of loops.

Yours Sincerely

Richard West

Edited by Nick Evan: Fixed formatting

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.