In C ++, the floating point operator % not defined for floating-point numbers.
Therefore, the condition in this clause is if
if (float(sqrt(b)) % 1 == 0) {
wrong.
It will be easier to record the next cycle.
unsigned int a; std::cin >> a; for ( unsigned int i = 1, b; ( b = i * i ) <= a; i++ ) std::cout << b << ' '; std::cout << std::endl;
There is no need to include the cmath header and use the sqrt function declared in it.
The program can be made more meaningful. For example,
#include <iostream> int main() { while ( true ) { std::cout << "Enter a non-negative number (0 - exit): "; unsigned int a; if ( not ( std::cin >> a ) || a == 0 ) break; for ( unsigned int i = 1, b; ( b = i * i ) <= a; i++ ) std::cout << b << ' '; std::cout << std::endl; } return 0; }
The dialogue with the program may look something like this.
Enter a non-negative number (0 - exit): 100 1 4 9 16 25 36 49 64 81 100 Enter a non-negative number (0 - exit): 50 1 4 9 16 25 36 49 Enter a non-negative number (0 - exit): 25 1 4 9 16 25 Enter a non-negative number (0 - exit): 0