#include "money.h"
using namespace std;

#include <iostream>

using namespace std;

money::money(int d, int c)
{
dollars = d;
cents = c;
}

void money::setMoney(int d, int c)
{
dollars = d;
cents = c;
}

void money::getMoney(int & d, int & c) const
{
d = dollars;
c = cents;
}

void money::print() const
{
cout << "\$" << dollars << ".";

if (cents < 10)
cout << "0";

cout << cents << endl;
}

int money::dollarsToCents() const
{
return (dollars * 100 + cents);
}

bool money::equalMoney(money otherMoney) const
{
return (dollars == otherMoney.dollars && cents == otherMoney.cents);
}

ostream & operator<<(ostream &out, const money &m)
{
int d, c;
m.getMoney(d,c);

out << "\$" << d << ".";

if (c == 0)
out << "00";
else if (c < 10)
out << "0" << c;
else
out << c;

return out;
}

istream& operator>>(istream& is, money& Money)
{
int d,c;
char ch;
is>>d>>ch>>c;
Money.setMoney(d,c);
return is;
}
money operator+(money a, money b)
{
money temp(a.dollars+b.dollars,a.cents+b.cents);
return temp;
}
bool operator==(money a, money b)
{
return (a.dollars==b.dollars && a.cents==b.cents);
}
bool operator!=(money a, money b)
{

return !(a==b);

}

#include <iostream>
#ifndef MONEY_H
#define MONEY_H

class money
{

public:
money(int = 0, int = 0);
void setMoney(int, int);
void getMoney(int&, int&) const;
void print() const; // in the form \$1.05
int dollarsToCents() const; // converts \$1.05 to 105 cents
bool equalMoney(money otherMoney) const; // checks if two money objects are equal
int dollars;
int cents;

};

ostream & operator<<(ostream &out, const money &m);
istream & operator>>(std::istream &in, const money &m);
money operator+(money, money);
bool operator==(money, money);
bool operator!=(money, money);
#endif

ok im getting a boat load of errors
1>c:\users\ezaz\desktop\money project\money project\money.h(24): error C2143: syntax error : missing ';' before '&'
1>c:\users\ezaz\desktop\money project\money project\money.h(24): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ezaz\desktop\money project\money project\money.h(24): error C2065: 'out' : undeclared identifier
1>c:\users\ezaz\desktop\money project\money project\money.h(24): error C2059: syntax error : 'const'
1>c:\users\ezaz\desktop\money project\money project\money.h(25): error C2143: syntax error : missing ';' before '&'
1>c:\users\ezaz\desktop\money project\money project\money.h(25): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\ezaz\desktop\money project\money project\money.h
1>c:\users\ezaz\desktop\money project\money project\money.h

there too many to post ,
but there are no red lines on the code .
I think you need std:: in front of the stream types in your header.

using namespace st
Ok i got the errors fixed and it compiles, but when i enter a value it goes to the second line then it crashes. i have no idea maybe you can look at my code and see what im not seeing
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167`` ``````header file #include #ifndef MONEY_H #define MONEY_H using namespace std; class money { public: money(int = 0, int = 0); void setMoney(int, int); void getMoney(int&, int&) const; int dollarsToCents() const; // converts \$1.05 to 105 cents bool equalMoney(money otherMoney) const; // checks if two money objects are equal private: int dollars; int cents; }; ostream & operator<<(ostream& cout, money right); istream & operator>>(istream& cin, money& right); money operator+(money, money); bool operator==(money, money); bool operator!=(money, money); #endif Cpp file #include "money.h" #include #include using namespace std; money::money(int d, int c) { dollars = d; cents = c; } void money::setMoney(int d, int c) { dollars = d; cents = c; } void money::getMoney(int & d, int & c) const { d = dollars; c = cents; } int money::dollarsToCents() const { return (dollars * 100 + cents); } bool money::equalMoney(money otherMoney) const { return (dollars == otherMoney.dollars && cents == otherMoney.cents); } ostream & operator<<(ostream& cout, money right) { int d, c; right.getMoney(d,c); cout << "\$" << d << "."; if (c == 0) cout << "00"; else if (c < 10) cout << "0" << c; else cout << c; return cout; } istream& operator>>(istream& cin, money& right) { int d,c; char ch; cin>>d>>ch>>c; right.setMoney(d,c); return cin; } money operator+(money left, money right) { money result; int rd,ld,rc,lc,resultd,resultc; left.getMoney(ld,lc); right.getMoney(rd,rc); resultd= ld+rd; resultc=lc+rc; result.setMoney(resultd,resultc); return result; } bool operator==(money right, money left) { return left.dollarsToCents()==right.dollarsToCents(); } bool operator!=(money left, money right) { return left.dollarsToCents()!=right.dollarsToCents(); } driver #include #include"money.h" using namespace std; int main() { money m1; money m2(10); int dollar,cent; cout<<"m1 created with default constructor:\t"<>m1; m1.getMoney(dollar,cent); cout<<"Now, m1 has "<>dollar; cout<<"Enter amount of cents for m2: "; cin>>cent; m2.setMoney(dollar,cent); cout<<"m1 + m2 = "<<(m1+m2)<
 when i enter a value it goes to the second line then it crashes

What do you mean by "the second line"? The second line of code? The second line of input? The second line of output?

Can you be more specific about what behaviour you're seeing?
i ment after i put in a dollar amount it doesnt output the second question , as soon as i press enter it doesnt ask the second question it just freezes for 5 seconds then it goes away and my compiler crashes
Topic archived. No new replies allowed.