Thread: Two error messages that I need help with.

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    73

    Two error messages that I need help with.

    The following code is to become a program that will return a given number as perfect, abundant, or deficient.

    Code:
    #include <iostream>
    #include <fstream>
    #include <cmath>
    using namespace std;
    
    //Prototypes
    void header();
    char FindSum();
    
    // Main program.
    int main()
    {
        int a;
    
        cout << header;
        cout << "Please enter a positive integer greater than 1 to continue, or enter a number less than or equal to 0 to quit:  ";
        cin >> a;
        if (a <= 0)
            return 0;
        else if (a == 1)
        {
            cout << "Invalid number. Please enter a valid number:  ";
            cin >> a;
        }
        while (a > 1)
        {
            cout << "Please enter another integer to caluclate, or enter 0 or a negative number to quit:  ";
            cin >> a;
            cout << FindSum(a, (a-1));
            if (a <= 0)
                    return 0;
            else if (a == 1)
                {
                cout << "Invalid number. Please enter a valid number:  ";
                cin >> a;
                }
        }
        return 0;
    }
    
    // Displays header as seen above
    void Header()
    {
        cout << "Trey Brumley" << endl;
        cout << "CMPS 1043-101" << endl;
        cout << "November 19, 2012" << endl;
        cout << "Program 4" << endl;
        cout << "=================" << endl;
    
        return;
    }
    
    // Returns single character 
    char FindSum(int x, int y, int sum = 0)
    {
        int z;
        char Class;
        for (y > 0; y = (x - 1); y--)
        {
            z = x / y;
    
            if (x % y == 0)
                sum += z;
        }
    
        if (sum == x)
            Class = 'P';
        else if (sum > x)
            Class = 'A';
        else
            Class = 'D';
    
        return Class;
    }
    However, every time I try to debug it on Visual Studio, I get the following error messages:

    Code:
    1>c:\users\trey\documents\visual studio 2010\projects\program 4\program 4\main.cpp(35): error C2660: 'FindSum' : function does not take 2 arguments
    1>c:\users\trey\documents\visual studio 2010\projects\program 4\program 4\main.cpp(64): warning C4552: '>' : operator has no effect; expected operator with side-effect
    I don't know where the problem is because it's not giving me any red lines to show where I'm going wrong. Help please!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > 1>c:\users\trey\documents\visual studio 2010\projects\program 4\program 4\main.cpp(35): error C2660: 'FindSum' : function does not take 2 arguments
    Make the prototype match the implementation.

    > 1>c:\users\trey\documents\visual studio 2010\projects\program 4\program 4\main.cpp(64): warning C4552: '>' : operator has no effect; expected operator with side-effect
    for (y > 0; y = (x - 1); y--)
    Perhaps you meant
    for ( y = (x - 1);y > 0; y--)

    But if you're initialising y in this way, there is no point in making it a parameter.
    Likewise, making sum a default parameter initialised to 0 is a poor, since it only ever acts as a local variable. Declare it as a local.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    73
    Quote Originally Posted by Salem View Post
    > 1>c:\users\trey\documents\visual studio 2010\projects\program 4\program 4\main.cpp(35): error C2660: 'FindSum' : function does not take 2 arguments
    Make the prototype match the implementation.
    I don't understand what you mean by that.

  4. #4
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Code:
    char FindSum();
    does not match
    Code:
    char FindSum(int x, int y, int sum = 0)
    And another cross-poster
    Last edited by rags_to_riches; 11-18-2012 at 04:39 PM.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    73
    Fixed those errors, now it's giving me these:


    Code:
    1>main.obj : error LNK2019: unresolved external symbol "void __cdecl header(void)" (?header@@YAXXZ) referenced in function _main
    1>C:\Users\Trey\documents\visual studio 2010\Projects\Program 4\Debug\Program 4.exe : fatal error LNK1120: 1 unresolved externals

  6. #6
    Registered User
    Join Date
    Nov 2012
    Posts
    73
    Closing thread. Problems resolved for outright errors. Different questions to be asked now.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    For those who don't know the solution, it's because the authot has misspelled the prototype ("header") and the implementation ("Header"). Remember: C++ is case sensitive! "header" is not the same as "Header"!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error messages
    By maxorator in forum Windows Programming
    Replies: 5
    Last Post: 11-08-2005, 02:24 PM
  2. ERROR messages
    By majoub in forum C Programming
    Replies: 2
    Last Post: 03-06-2005, 12:20 PM
  3. XP error messages
    By chris1985 in forum Windows Programming
    Replies: 2
    Last Post: 01-12-2005, 02:37 PM
  4. Different error messages...
    By EvBladeRunnervE in forum Networking/Device Communication
    Replies: 2
    Last Post: 03-29-2004, 08:01 PM
  5. Need Help With Error Messages.
    By damarshal1 in forum C++ Programming
    Replies: 9
    Last Post: 05-05-2003, 02:31 PM