problem in number tower question

question:write a program that keeps accepting number and prints their square one at a time…
how do we know how many times loop should be applied?
link: http://www.codechef.com/WORKSHOP/problems/START03

use getline function function to read input as string
and check for empty string i.e 0 length string to break your code or you can say to end your program so that it cant take further input;

Use getline function in c++…take the inputs as string…when u get the string as “”…then break…
for problems related to integer operations on strings…
convert string to integer using stringstreams…for example

#include
#include

int main()
{
using namespace std;

string s = “1234”;
stringstream ss(s); // Could of course also have done ss(“1234”) directly.

int i;
ss >> i;
cout << i << endl;

return 0;
}

now ur string is converted to integer…

you can use the return value of scanf() to stop taking input after all test cases…