first time c++ prime and perfect

Write your question here.
i cant seem to understand how to place number to plug in on their own and be able to use a number being plugged in(Output a list of all divisors of numbers that are not prime and a list of divisors of all perfect numbers. Format your output so there are between 5 and 10 numbers per line .) if you can just explain that would be great really having trouble
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
  #include <iostream>
#include <string>
#include <iomanip>
using namespace std;
//get their number
int main()
{
    {
int  perfectnumber;
int number;
char response, prime;

cout << "Not sure if its a prime number or perfect number." << endl;
cout << "Would you like to find out if your number is prime or perfect?" << endl;
cin >> response;

cout << "

if (response == 'Y' || response == 'y')
{
cout << "Please enter any number you would like to check" << endl;
cin >> number;
}
else if (response == 'n' || response == 'N')
{
cout << "thanks come try me again soon!" << endl;
system("pause");
return 0;
}
else if (response != 'y' || response != 'Y' || response != 'N' || response != 'n' )
{
cout << "wrong input try again" << endl;
system ("pause");
}
//prime
     if ((number / 1 == number) && (number / number == 1))
    {
        cout << "It is a prime number!" << endl;
}
     else if ((number % 2 == 0 || number % 3 == 0 || number % 4 == 0 || number % 5 == 0 || number % 6 == 0 || number % 7 == 0 || number % 8 == 0 || number % 9 == 0))
{
cout << "Not a prime :(" << endl;
}
//perfect number
{
    int i=1,sum=0;
    while(i<number){
         if(number%i==0)
               sum=sum+i;
              i++;
  }
  if(sum==number)
         cout << i  <<  " is a perfect number!";
  else
         cout << i << " is not a perfect number :(";
  system("pause");
  return 0;
}
    }
} 
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// prime or perfect
#include <iostream>
using namespace std;
void isPrime(int);
void isPerfect(int);

int main( )
{
unsigned int n;
cout << "enter a number to see isPrime or isPerfect: ";
cin >> n;	
isPrime(n);
isPerfect(n);
	
return 0;
}

void isPrime(int n)
{
	cout << "\nin isPrime function: ";
	bool b=true;
	for(int i=2; i<n; i++)
	if(n%i==0)	
		b=false;	
	
	if(b) cout << "Prime.\n";
	else cout << "not Prime.\n";
}

void isPerfect(int n)
{
	cout << "\nin isPerfect function: ";
	int sum=0;
	for(int i=1; i<n; i++)
	if(n%i==0)	
		sum+= i;
	 
	if(sum==n) 
 		cout << "Perfect.\n";
	else cout << "not Perfect.\n"; 	
}
so i made it more complicated then it really is?
the thing is i know about bool and everything from watching tutorials online but since the teacher has not gone over it we gotta do it without void and bool. this is my first time making a program like this.
do you think i'm in the right direction anup30? with what i did.
and wow (unsigned int) didn't know i could use that.
really appreciate your help i'm going to see if i can use your formula without bool.
and if you know any video that can teach me c++ because my teacher is really complicating things and i'm scared of asking her for help because she tends to criticize us to other students because were bad.
sorry for writing so much first time looking for help
Last edited on
Topic archived. No new replies allowed.