C++ prime perfect prog formulas not working

pretty new to this,
structure and input formatting is correct but formulas always answer not prime not perfect. any suggestions?

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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

	int main()

{
	int sum= 0;
	int Number;
	int i = 2;
	int countA;
	int countB;
	string runagain;
	bool run = true;
	bool prime = true;
	bool perfect = false;
		
	while (run == true)

	{
		
		cout << "Enter a number" << endl;
	     cin >> Number;
	     cout<<"The number you entered is: "<<Number<< endl;
	

// perfect
		for(i = 1; i <= Number/2; ++i)
    {
        if((Number%i) == 0)
        {
            sum+=i;

	      }

	    if(sum==Number)
	     cout<< "The number you entered is a Perfect Number"<<endl;
	    else
	     cout<< "The number you entered is not a Perfect Number"<<endl;
	    
      
// prime
		for(i=2; i<Number; i++)
	    {
	     if  ((Number%i)==0)
	      prime=false;
	     }
	     
	    if (prime == true)
	    cout<< "The number you entered is a Prime Number"<<endl;
	   
	    else
	    cout<< "The number you entered is not a Prime Number"<<endl;
		
	 
// divisors
	cout << "the divisors for " << Number << " are: " << endl;
for(i=1; i<Number; i++)
{
if(Number%i==0)
{
cout << i << "\t" ;
sum = sum + i;
}
}

		
		

		
// retry	
    cout << endl;
	cout << "Would you like to test another integer? (Y/N)" << endl; 
	cin >> runagain;

	if(runagain == "y" || runagain =="Y" || runagain == "Yes")
	run = true;
	
	else
	run = false;

	
	}
	}
	system ("pause");
	    return (0);

	}
Topic archived. No new replies allowed.