Hello, I`m just starting to get into the basics of C++ and I have to create a following program - basically the user has to input an integer and a digit of their choice and the program has to check whether the square of that integer contains that specific digit or not, and if it does then how many of them are in that square. The result has to be outputted on the screen and the number has to be split into digits with the modulus operation.
This is what I have done so far
#include <iostream>
using namespace std;
int main()
{
int number,digit,square,remainder,ok;
do
{
start: {}
cout << "Input an integer!" << endl;
cin >> number;
if (number <= 0)
{
cout << "You entered incorrect data, input an integer!" << endl;
goto start;
}
else
cout << "Input a digit!" << endl;
cin >> digit;
square = number*number;
do
{
remainder = number %10;
number = number / 10;
} while (square>1);
if (remainder == digit)
cout << "Square of "<< number <<" contains "<< digit << endl;
else
cout << "Square of "<< number <<" does not contain "<< digit << endl;
cout << "Repeat the program (1) or end it (0)?" << endl;
cin >> ok;
} while (ok == 1);
return 0;
}
It also has to be repeatable, which I have kinda figured out, also if the input is wrong, like a negative number, the program has to let you know, is goto the right thing for that?
I don`t know how to count the specific digits in the given number and I think my code is off, too. So any help or directions on what I should be working with will be appreciated. Thanks in advance!