I get the error messages:
program17.cpp:108: error: ISO C++ forbids comparison between pointer and integer
program17.cpp:110: error: `num' was not declared in this scope
program17.cpp:110: warning: unused variable 'num'
the program is supposed to find the factors of the number, and output if it is a perfect number (factors add up to itself) or not.
here is my code, some insight would be appreciated.
#include <iostream>
using namespace std;
bool perfTest ( int NUM );
void factorPrint ( int NUM );
int main ()
{
int dig;
int num;
int counter = 0;
cout << "How many numbers should be tested?";
cin >> dig;
while ( dig < 1 )
{
cout << "How many numbers should be tested?";
cin >> dig;
while (counter != dig )
{
cout << "Please enter a possible perfect number: ";
cin >> num;
if ( perfTest == false)
{
cout << "NOT PERFECT" << endl;
counter++;
}
}
}
return 0;
}
bool perfTest ( int NUM )
{
int X;
int Y;
int TOT = 0;
int count;
bool rVal = false;
X = NUM;
count = X;
while ( count != 1 )
{
if ( NUM % count == 0 )
{
Y = NUM / count;
TOT = TOT + Y;
}
count--;
}
if ( TOT == NUM )
{
rVal = true;
}
return rVal;
}
void factorPrint ( int NUM )
{
int X;
int Y;
int count;
X = NUM;
count = 0;
while ( count != NUM )
{
if ( NUM % count == 0 )
{
Y = NUM / count;
}
count++;
}
if ( perfTest == 'true' )
{
cout << main(num) << ":" << Y << endl;;
}
return;
}
program17.cpp:108: error: ISO C++ forbids comparison between pointer and integer
program17.cpp:110: error: `num' was not declared in this scope
program17.cpp:110: warning: unused variable 'num'
the program is supposed to find the factors of the number, and output if it is a perfect number (factors add up to itself) or not.
here is my code, some insight would be appreciated.
#include <iostream>
using namespace std;
bool perfTest ( int NUM );
void factorPrint ( int NUM );
int main ()
{
int dig;
int num;
int counter = 0;
cout << "How many numbers should be tested?";
cin >> dig;
while ( dig < 1 )
{
cout << "How many numbers should be tested?";
cin >> dig;
while (counter != dig )
{
cout << "Please enter a possible perfect number: ";
cin >> num;
if ( perfTest == false)
{
cout << "NOT PERFECT" << endl;
counter++;
}
}
}
return 0;
}
bool perfTest ( int NUM )
{
int X;
int Y;
int TOT = 0;
int count;
bool rVal = false;
X = NUM;
count = X;
while ( count != 1 )
{
if ( NUM % count == 0 )
{
Y = NUM / count;
TOT = TOT + Y;
}
count--;
}
if ( TOT == NUM )
{
rVal = true;
}
return rVal;
}
void factorPrint ( int NUM )
{
int X;
int Y;
int count;
X = NUM;
count = 0;
while ( count != NUM )
{
if ( NUM % count == 0 )
{
Y = NUM / count;
}
count++;
}
if ( perfTest == 'true' )
{
cout << main(num) << ":" << Y << endl;;
}
return;
}