3 errors for my C++ !

This is a discussion on 3 errors for my C++ ! within the C++ Programming forums, part of the General Programming Boards category; Hey guys! I got my first C++ homework assignment and the homework assignment I have to do is: A perfect ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    1

    Question 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
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    156
    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; 
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 11:50 AM
  2. Winsock compilation errors
    By jmd15 in forum Networking/Device Communication
    Replies: 2
    Last Post: 08-03-2005, 09:00 AM
  3. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 03:57 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. Help me with these errors... :-(
    By major_small in forum C++ Programming
    Replies: 6
    Last Post: 09-07-2003, 09:18 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21