Like Tree1Likes
  • 1 Post By rags_to_riches

Two error messages that I need help with.

This is a discussion on Two error messages that I need help with. within the C++ Programming forums, part of the General Programming Boards category; The following code is to become a program that will return a given number as perfect, abundant, or deficient. Code: ...

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

    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,334
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    64
    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
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    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 03:39 PM.
    Salem likes this.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    64
    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
    64
    Closing thread. Problems resolved for outright errors. Different questions to be asked now.

  7. #7
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,167
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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

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