I need help with this program as soon as possible

I am lost as to were to put the for or if of else in this program

Page 1 of 1

6 Replies - 533 Views - Last Post: 04 November 2008 - 08:24 PM Rate Topic: -----

#1 yunusabd  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 104
  • Joined: 25-October 08

I need help with this program as soon as possible

Posted 04 November 2008 - 06:00 PM

//Modify the money class included in this document to include an increment and decrement operator.
//These operators need to function both as prefix operators and postfix operators and should return a
//money object so that they can be used in assignment functions. They will increment or decrement
//ONLY the amount of the private dollars member by one. A flow chart is not needed for this
//assignment. After changing the class use the following code in the main function to test it:

//Money mon1, mon2;
//mon1.getMoneyInt();
//mon2 = ++mon1;
//mon2.putMoneyInt();
//mon2++;
//mon2.putMoneyInt();
//mon1 = mon2--;
//mon1.putMoneyInt();
//--mon1;
//mon1.putMoneyInt();

//Grading:
//2 – General, compiles, comments, proper indentation, etc
//2 – Declaration of operator functions
//2 – Code of operator functions
//Source code for money.cpp:

#include <iostream>
using namespace std;
class Money
{
private:
int dollars, quarters, dimes, nickels, pennies;
float cents;
public:
Money() : dollars(0),quarters(0),dimes(0),nickels(0),pennies(0),cents(0)
{}
void getMoneyInt();
void putMoneyInt();
void getMoneyDec();
void putMoneyDec();
Money addMoney(Money money2);
};
int main()
{
return 0;
}
void Money::putMoneyDec()
{
cout << "You have $" << dollars + cents << endl;
}
void Money::getMoneyDec()
{
float money;
cout << "Enter the amount of money you have as a decimal: ";
cin >> money;
dollars = static_cast<long>(money);
cents = money - dollars;
}
Money Money::addMoney(Money money2)
{
Money temp;
temp.dollars = dollars + money2.dollars;
temp.quarters = quarters + money2.quarters;
temp.dimes = dimes + money2.dimes;
temp.nickels = nickels + money2.nickels;
temp.pennies = pennies + money2.pennies;
return(temp);
}
void Money::putMoneyInt()
{
cout << "You have " << dollars << " dollars, " << quarters << " quarters, "
<< dimes << " dimes, " << nickels << " nickels and " << pennies
<< " pennies.\n";
}
void Money::getMoneyInt()
{
cout << "Enter the number of dollars you have (whole numbers only): ";
cin >> dollars;
cout << "Enter the number of quarters you have (whole numbers only): ";
cin >> quarters;
cout << "Enter the number of dimes you have (whole numbers only): ";
cin >> dimes;
cout << "Enter the number of nickels you have (whole numbers only): ";
cin >> nickels;
cout << "Enter the number of pennies you have (whole numbers only): ";
cin >> pennies;
}



** Edit ** :code:

Is This A Good Question/Topic? 0
  • +

Replies To: I need help with this program as soon as possible

#2 salindor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 46
  • View blog
  • Posts: 301
  • Joined: 10-November 06

Re: I need help with this program as soon as possible

Posted 04 November 2008 - 06:05 PM

First thing first place all code inside of code braces. With your code like that it is impossible to read. Without the code braces, indentation is lost.

I really don't understand why you think a for/if or whatever. So instead I am going to ask this question back at you.

Do you have any code you need repeated more than once? (for loop)

Do you have any code which is different based on something else (if statement)

Salindor
Was This Post Helpful? 0
  • +
  • -

#3 hellCoder++  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 04-November 08

Re: I need help with this program as soon as possible

Posted 04 November 2008 - 06:47 PM

Like Salindor said, you need to put your code inside [code] attributes.
We need to see your work before helping you, so do the work first and if you get stuck with some compile errors or logic error then we can help you!
Thanks,
Was This Post Helpful? 0
  • +
  • -

#4 yunusabd  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 104
  • Joined: 25-October 08

Re: I need help with this program as soon as possible

Posted 04 November 2008 - 07:04 PM

Is that better I am not sure what you want as far as on my part. I know a little C but not C++ so I am a little lost as to were to start
the output is supposed to be
Enter the amount of dollars you have (whole numbers only): 1
Enter the amount of quarters you have (whole numbers only): 2
Enter the amount of dimes you have (whole numbers only): 3
Enter the amount of nickels you have (whole numbers only): 4
Enter the amount of pennies you have (whole numbers only): 5

You have entered 2 dollars, 2 quarters, 3 dimes, 4 nickels, and 5 pennies.

You have entered 3 dollars, 2 quarters, 3 dimes, 4 nickels, and 5 pennies.

You have entered 2 dollars, 2 quarters, 3 dimes, 4 nickels, and 5 pennies.

You have entered 1 dollars, 2 quarters, 3 dimes, 4 nickels, and 5 pennies.


This is were I think that I would have to use a for statement like
for (money=0; money==input ; i++)
for (money=0; money==input ; i--)
for (money=0; money==input ; i++)

But as I said I am familiar with C and am still learning so I am a little lost in the C++ functions I really just need some explanation not the work doe and I put all this code and notes here so that you would know what it is.



//Modify the money class included in this document to include an increment and decrement operator.
//These operators need to function both as prefix operators and postfix operators and should return a
//money object so that they can be used in assignment functions. They will increment or decrement
//ONLY the amount of the private dollars member by one. A flow chart is not needed for this
//assignment. After changing the class use the following code in the main function to test it:

//Money mon1, mon2;
//mon1.getMoneyInt();
//mon2 = ++mon1;
//mon2.putMoneyInt();
//mon2++;
//mon2.putMoneyInt();
//mon1 = mon2--;
//mon1.putMoneyInt();
//--mon1;
//mon1.putMoneyInt();

//Grading:
//2 – General, compiles, comments, proper indentation, etc
//2 – Declaration of operator functions
//2 – Code of operator functions
//Source code for money.cpp:

#include <iostream>
using namespace std;
class Money
{
    private:
    int dollars, quarters, dimes, nickels, pennies;
    float cents; 
    public: 
    
    Money() : dollars(0),quarters(0),dimes(0),nickels(0),pennies(0),cents(0)
{}
    void getMoneyInt();
    void putMoneyInt();
    void getMoneyDec();
    void putMoneyDec();
    Money addMoney(Money money2);
};
int main()
{
    return 0;
}
    void Money::putMoneyDec()
{
     cout << "You have $" << dollars + cents << endl;
}
    void Money::getMoneyDec()
{
    float money;
    cout << "Enter the amount of money you have as a decimal: "; 
    cin >> money;
    dollars = static_cast<long>(money);
    cents = money - dollars;
}
    Money Money::addMoney(Money money2)
{
    Money temp;
    temp.dollars = dollars + money2.dollars;
    temp.quarters = quarters + money2.quarters;
    temp.dimes = dimes + money2.dimes;
    temp.nickels = nickels + money2.nickels;
    temp.pennies = pennies + money2.pennies;
    return(temp);
}
    void Money::putMoneyInt()
{
    cout << "You have " << dollars << " dollars, " << quarters << " quarters, "
    << dimes << " dimes, " << nickels << " nickels and " << pennies
    << " pennies.\n";
}
    void Money::getMoneyInt()
{
    cout << "Enter the number of dollars you have (whole numbers only): ";
    cin >> dollars;
    cout << "Enter the number of quarters you have (whole numbers only): ";
    cin >> quarters;
    cout << "Enter the number of dimes you have (whole numbers only): ";
    cin >> dimes; 
    cout << "Enter the number of nickels you have (whole numbers only): ";
    cin >> nickels; 
    cout << "Enter the number of pennies you have (whole numbers only): ";
    cin >> pennies;
}



I just indented everything and when I posted it, it did not indent. ?????

** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#5 salindor  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 46
  • View blog
  • Posts: 301
  • Joined: 10-November 06

Re: I need help with this program as soon as possible

Posted 04 November 2008 - 08:01 PM

If you knew C, then you wouldn't be asking for help. I have spent quite abit of time coding in pure C, so trust me; this problem your having would be in both C and C++.

You never placed your code within the [code ] [/code ] statements; hence your code will not indent until you do.

Your for loops are abit wierd they should be following the following pattern
for(<initializer>; <test for continuing>; <incrementor>)
{

}



So here is an example
for (i=0; i<10; i++)
{
}



Notice I use the same variable in all three parts. It is extremely rare to not do that and should only be done with careful consideration (and I would argue deserves a comment explaining what your doing).
Was This Post Helpful? 0
  • +
  • -

#6 UG Cyber  Icon User is offline

  • D.I.C Addict

Reputation: 32
  • View blog
  • Posts: 546
  • Joined: 24-July 08

Re: I need help with this program as soon as possible

Posted 04 November 2008 - 08:13 PM


//Modify the money class included in this document to include an increment and decrement operator.
//These operators need to function both as prefix operators and postfix operators and should return a
//money object so that they can be used in assignment functions. They will increment or decrement
//ONLY the amount of the private dollars member by one. A flow chart is not needed for this
//assignment. After changing the class use the following code in the main function to test it:

//Money mon1, mon2;
//mon1.getMoneyInt();
//mon2 = ++mon1;
//mon2.putMoneyInt();
//mon2++;
//mon2.putMoneyInt();
//mon1 = mon2--;
//mon1.putMoneyInt();
//--mon1;
//mon1.putMoneyInt();

//Grading:
//2  General, compiles, comments, proper indentation, etc
//2  Declaration of operator functions
//2  Code of operator functions
//Source code for money.cpp:

#include <iostream>
using namespace std;
class Money
{
    private:
    int dollars, quarters, dimes, nickels, pennies;
    float cents; 
    public: 
    
    Money() : dollars(0),quarters(0),dimes(0),nickels(0),pennies(0),cents(0)
{}
    void getMoneyInt();
    void putMoneyInt();
    void getMoneyDec();
    void putMoneyDec();
    Money addMoney(Money money2);
};
int main()
{
    return 0;
}
    void Money::putMoneyDec()
{
     cout << "You have $" << dollars + cents << endl;
}
    void Money::getMoneyDec()
{
    float money;
    cout << "Enter the amount of money you have as a decimal: "; 
    cin >> money;
    dollars = static_cast<long>(money);
    cents = money - dollars;
}
    Money Money::addMoney(Money money2)
{
    Money temp;
    temp.dollars = dollars + money2.dollars;
    temp.quarters = quarters + money2.quarters;
    temp.dimes = dimes + money2.dimes;
    temp.nickels = nickels + money2.nickels;
    temp.pennies = pennies + money2.pennies;
    return(temp);
}
    void Money::putMoneyInt()
{
    cout << "You have " << dollars << " dollars, " << quarters << " quarters, "
    << dimes << " dimes, " << nickels << " nickels and " << pennies
    << " pennies.\n";
}
    void Money::getMoneyInt()
{
    cout << "Enter the number of dollars you have (whole numbers only): ";
    cin >> dollars;
    cout << "Enter the number of quarters you have (whole numbers only): ";
    cin >> quarters;
    cout << "Enter the number of dimes you have (whole numbers only): ";
    cin >> dimes; 
    cout << "Enter the number of nickels you have (whole numbers only): ";
    cin >> nickels; 
    cout << "Enter the number of pennies you have (whole numbers only): ";
    cin >> pennies;
}


Quote

I just indented everything and when I posted it, it did not indent. ?????


INDENTS DON'T MATTER IF YOU DONT APPLY THE [code] TAGS
:code: :angry:
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5234
  • View blog
  • Posts: 27,024
  • Joined: 10-May 07

Re: I need help with this program as soon as possible

Posted 04 November 2008 - 08:24 PM

View Postyunusabd, on 4 Nov, 2008 - 08:04 PM, said:

I just indented everything and when I posted it, it did not indent. ?????

Use code tags...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1