I am supposed to write a program that can tell if a positive integer is abundant,deficient, or perfect. But I really don't understand what is wrong here:
#include <iostream>
usingnamespace std;
int main()
{
int number,counter,total;
/* Asks for user input*/
cout << "Welcome to the program Factors, this program check to see\n"
<< "if the number you enter is deficent, perfect or abundant\n"
<< "this program will read in numbers till you enter -1 and or negitive numbers";
while (number > -1)
{
counter = 1;
cout << endl;
cout << "Please enter a Integer:\n";
cin >> number;
cout << endl;
if (number % counter == 0)
{
total= counter + (number % counter);
cout << total << "+";
counter++;
}
if (number < total)
{
cout << endl;
cout << number <<" is abundant\n";
}
elseif (number>total)
{
cout << endl;
cout << number << " is deficient\n";
cout << endl;
}
else
{
cout << endl;
cout << number << " is Perfect\n";
cout << endl;
}
}
cout<< endl << endl << endl;
system ("pause");
return 0;
}
I there something wrong with my variables? What am I missing?
#include <iostream>
usingnamespace std;
int main()
{
//initializing int number as 0
int number = 0,counter,total;
/* Asks for user input*/
cout << "Welcome to the program Factors, this program check to see\n"
<< "if the number you enter is deficent, perfect or abundant\n"
<< "this program will read in numbers till you enter -1 and or negitive numbers";
while (number > -1)
{
cout << endl;
cout << "Please enter a Integer:\n";
cin >> number;
if (number < 0) { break; }
cout << endl;
counter = 1; total = 0;
while (counter < number) {
if (number % counter == 0) {
cout << total << "+" << counter;
total += counter;
cout << "=" << total << endl;
}
counter++;
}
if (number < total){
cout << endl;
cout << number <<" is abundant\n";
} elseif (number>total) {
cout << endl;
cout << number << " is deficient\n";
cout << endl;
} else {
cout << endl;
cout << number << " is Perfect\n";
cout << endl;
}
}
cout<< endl << endl << endl;
return 0;
}