Thread: Fatal errors

  1. #1
    Registered User
    Join Date
    May 2002
    Posts
    11

    Question Fatal errors

    I am getting an error when running my program. I can't seem to see the problem. Can someone please help.

    Compiling...
    functions.cpp
    h:\documents and settings\administrator\my documents\c++\nsp\money.h(29) : fatal error C1070: mismatched #if/#endif pair in file 'h:\documents and settings\administrator\my documents\c++\nsp\money.h'
    main.cpp
    h:\documents and settings\administrator\my documents\c++\nsp\money.h(29) : fatal error C1070: mismatched #if/#endif pair in file 'h:\documents and settings\administrator\my documents\c++\nsp\money.h'
    Error executing cl.exe.

    NSP.exe - 2 error(s), 0 warning(s)
    //**************************************************

    #ifndef MONEY_H
    #define MONEY_H
    #include <iostream.h>
    #include <iomanip.h>
    #include <string.h>
    #include <assert.h>

    enum {MAX_LINE = 1024};
    #define NN ""

    class Money
    {
    public:
    enum {DD=0, CC=0};
    Money(long d =DD, int c = CC, const char *name = NN);
    ~Money ();
    void SetMoney(long d =DD, int c = CC, const char *name = NN);
    void print(long,int,char) const;
    void cinMoney();

    private:
    long theDollars;
    int theCents;
    char *theName;
    void Carry();
    void setName(const char *str);

    }; //endif // MONEY_H



    void Money::setName(const char *str)
    {
    //this function allocates memory to hold the contents of string str,
    //assigns its address to theName and copies contents of str to allocated
    //memory.

    strcpy (theName, str);
    }

    void Money::Carry(Money *m1)
    {
    //this function make sure the sign of the cents matches that of the dollars
    //after the parts have been added up seperately.

    while ((m1->cents <0)&&(m1->dollars >0))
    {
    --m1->dollars;
    ml->cents += 100;
    }
    while ((m1->cents > 0)&&(m1->dollars <0))
    {
    ++m1->dollars;
    ml->cents -= 100;
    }
    m1-> dollars += m1->cents/100;
    m1->cents %= 100;

    }

    void Money::SetMoney(long d = DD, int cents = CC, const char *name = NN)
    {
    // this function sets all the components of the object Money. This
    // function calls setName() to set up theName.
    thedollars = DD;
    thecents = CC;
    setName(NN);
    carry();

    }



    Money::Money (long d = DD, int cents = CC, const char *name = NN)
    {
    //this constructor has three arguments (Its also a default constructor).
    //this function call setMoney() to initilize object's components.

    setMoney(d,cents,&name);

    }

    Money::~Money()
    {
    //this destructor deallocates dynamic memory (address stored in theName).

    cout<< "*** Money Destructor: \t << "("<< dollars <<','<< cents <<','<<\"description<<endl;
    }


    void Money:rint (long dollars, int cents , char theName) const
    {
    //this function displays object's components.
    cout<< "*** Money Constructor:\t" << "("<< dollars <<","<< cents <<","<<"description\"<< ')' <<endl;
    cout<< '$'<< Money.dollars << '.' ;
    cout<< setfill('0') << setw (2) Money.cents;
    cout<< ' ' Money.theName << endl;
    }


    void Money::cinMoney()
    {
    //this fuction prompts user to enter the money components and assigns
    //them to object's data. This function reads input from stdin and uses
    //default values if input is invalid. This function calls setMoney() to
    //store values in the object.


    while(true)
    {
    cout << "Enter [dollars : cents] amounts and next line description:"
    cin >> theDollars >> theCents >> theName;
    if(!cin.good())
    {
    cout<< "Invalid Amount format" << endl;
    cin.clear();
    cin.ignore(MAX-LINE, '\n');
    break;
    }

    setMoney(dollars,cents,theName
    }
    }



    //#include "money1.h"
    int main()
    {
    //PART 1

    Money m1;
    ml.print();
    cout << endl;
    Money m2 (400);
    m2.print();
    cout << endl;
    Money m3 (500,50);
    m3.print();
    cout << endl;
    Money m4 (12,99,"Breakfast at Wexford");
    m4.print();
    cout << endl;
    Money m5 (-1,-10, "Amount oweing to Susan");
    m5.print();
    cout << endl;
    m5.setMoney(-100,1, "Amount oweing to John");
    m5.print();
    cout << endl;
    Money m6 (0, -25,"Amount oweing to Melanie" );
    m6.print();
    cout << endl;

    //PART 2

    char c;
    Money in;

    cout <<"This program will continue to asking for [dollar:cent] amounts"
    "and descriptions." << endl;
    while(true)
    {
    in.cinMoney();
    cout << "\nYou entered: "<<endl;
    in.print();
    cout << "\n\nDo you want to contine? (Y/N)";
    cin >> c;
    if (('Y'!= c)&&('y' != c))
    break;
    }

    in.print();
    return 0;
    }

  2. #2
    Registered User Cela's Avatar
    Join Date
    Jan 2003
    Posts
    362
    >>#ifndef MONEY_H
    You need an #endif somewhere in your code :-)
    *Cela*

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    1,109
    also, code tags...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. global namespace errors
    By stubaan in forum C++ Programming
    Replies: 9
    Last Post: 04-02-2008, 03:11 PM
  2. Ten Errors
    By AverageSoftware in forum Contests Board
    Replies: 0
    Last Post: 07-20-2007, 10:50 AM
  3. Header File Errors...
    By Junior89 in forum C++ Programming
    Replies: 5
    Last Post: 07-08-2007, 12:28 AM
  4. Unknown Errors in simple program
    By neandrake in forum C++ Programming
    Replies: 16
    Last Post: 04-06-2004, 02:57 PM
  5. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM