- #1
gbsboard
- 4
- 0
Ok I've been having a lot of trouble with this program, I am also very new to C++. The program requires to have 4 functions 1 main, 1 svr, 2 void functions
any kind of loop (for loop preferred) in the main function so that a user can enter any number of positive integers in the main function. One function is called sum_of_divisors which accepts an integer and returns the sum of its perfect divisors.
The program also prints out the input value as well as a message indicating whether the number is perfect or not
Example
Enter Number you want to test: 12
Sum of Divisor = 16
12 is not a perfect number
Enter Number you want to test: 6
Sum of Divisor = 6
6 is a perfect number
So far I have as my code
any kind of loop (for loop preferred) in the main function so that a user can enter any number of positive integers in the main function. One function is called sum_of_divisors which accepts an integer and returns the sum of its perfect divisors.
The program also prints out the input value as well as a message indicating whether the number is perfect or not
Example
Enter Number you want to test: 12
Sum of Divisor = 16
12 is not a perfect number
Enter Number you want to test: 6
Sum of Divisor = 6
6 is a perfect number
So far I have as my code
Code:
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
//File Name: Perfect Numbers
//Author: ********
//Email Address: ***********
//Homework Number: 3
//Description: Tests input number to see whether or not they
//are perfect numbers.
//Last Changed: feb 2, 2011
#include <iostream>
using namespace std;
//* * * * * * * * * * * * * * * * * * * * * * * * * *
//* Funtion: get_data
//* purpose: reads the value used
//*
//* parameters: Num1 - the first number
//* calls: None
//* * * * * * * * * * * * * * * * * * * * * * * * * * *
void get_data (int& num1);
//* * * * * * * * * * * * * * * * * * * * * * * * * *
//* Funtion: Sum of Divisors
//* purpose: Figures out whether what the divisors are
//* parameters: Divisor - gets the number
//*
//* calls: None
//* * * * * * * * * * * * * * * * * * * * * * * * * * *
void sum_of_divisors(int num1);
//* * * * * * * * * * * * * * * * * * * * * * * * * *
//* Funtion: Results
//* purpose: Shows the results of the function
//* parameters: Divisor - shows the perfect
//*
//* calls: get_data
//* * * * * * * * * * * * * * * * * * * * * * * * * * *
void show_results (int num1);
int num1;
int main()
{
int num1;
get_data(num1);
while (num<=0);
for(int divisor=1; divisor<=num1; divisor++)
{
show_results(num1)
get_data(num1)
}
return(0);
}
void get_data(int& num1)
{
using namespace std;
cout <<"\n Enter number to test to see if it is a perfect number ";
cin >> num1;
}
void sum_of_divisors(int num1)
{
int sum=0;
for(int divisor = 1; divisor <=(num1 / 2); divisor++)
if(num1 % divisor == 0)
sum += divisor;
return;
void show_results(int num1)
{
sum_of_divisors();
cout<<" \n\nThe perfect divisors for the input number \n\n"<<
cout<<" Number being tested: " << num1 <<" Divisors: " << sum_of_divisors <<endl<<endl;
}