-
3 errors for my C++ !
Hey guys! I got my first C++ homework assignment and the homework assignment I have to do is: A perfect number is a positive integer such that the sum of the proper divisors equals the number.
I have received 3 errors on this and could you point me out to those errors and show me how to correct it?
Here is the coding I have done so far:
-------Start--------
#include <iostream>
using namespace std;
int main()
{
int cotinue=1;
int main_num=0, test_num, divisor, sum_of_divisors;
int valid_input;
cout<< Enter;
while(cotinue == 1)
{
valid_input=0;
while(valid_input == 0)
{
cout<<"\n\nPlease input an integer: \n";
cin>>main_num;
}
cout<<"The perfect positive numbers that are less than or equal to "<<main_num<<" include:\n";
for(test_num=1; test_num <= main_num; ++test_num)
{
for(divisor=1, sum_of_divisors=0; (divisor <= ((test_num / 2)+1)); ++divisor)
{
if((test_num % divisor) == 0)
{
sum_of_divisors = sum_of_divisors + divisor;
}
}
if(sum_of_divisors == test_num)
{
cout<<<<test_num<<"\n";
}
}
return 0;
}
-------End--------
Let me know
Thanks :)
Brad
-
I don't know if it works but it will compile. The changes I made are between the CHANGED tags.
Code:
#include <iostream>
using namespace std;
int main()
{
int cotinue=1;
int main_num=0, test_num, divisor, sum_of_divisors;
int valid_input;
cout<< [ CHANGED ]"Enter" << endl[ CHANGED put in "" around enter and added << endl ];
while(cotinue == 1)
{
valid_input=0;
while(valid_input == 0)
{
cout<<"\n\nPlease input an integer: \n";
cin>>main_num;
}
cout<<"The perfect positive numbers that are less than or equal to "<<main_num<<" include:\n";
for(test_num=1; test_num <= main_num; ++test_num)
{
for(divisor=1, sum_of_divisors=0; (divisor <= ((test_num / 2)+1)); ++divisor)
{
if((test_num % divisor) == 0)
{
sum_of_divisors = sum_of_divisors + divisor;
}
}
if(sum_of_divisors == test_num)
{
cout[ CHANGED ]<<[ CHANGED there were <<<< I removed << leaving << ]test_num<<"\n";
}
}
[ CHANGED ]} [ CHANGED did not have all the required braces your code blocks did not match ]
return 0;
}