- #1
mr.me
- 49
- 0
Heres my problem, step one I've solved. Step two only ever returns the original newRoot*newRoo and I don't understand how to correct itTo demonstrate event controlled loops use arithmetic to create:
1.Create a sequence to determine the next largest perfect square
2.Create another sequence to determine the next smallest perfect square for a value less than 1000
My code:
1.Create a sequence to determine the next largest perfect square
2.Create another sequence to determine the next smallest perfect square for a value less than 1000
My code:
Code:
#include <iostream>
#include <math.h>
#include <iomanip>
using std::cout;
using std::cin;
using std::endl;
main()
{
cout << "Enter a number for which to find the next largest perfect square: ";
int number;
cin >> number;
int sqRoot = 1;
while (sqRoot*sqRoot < number) // sqRoot is too small
sqRoot++; // try the next number
cout << sqRoot*sqRoot << endl;
cout<< "Enter a number for which to find the next smallest perfect square: ";
int newNumber;
cin>>newNumber;
int newRoot =1000;
while (newRoot*newRoot < 1000 )
newRoot-+newRoot;
cout<< newRoot*newRoot<<endl;
}
Last edited: