Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Currency Data Type C++
    primarykey
    data
    text
    <p>my homework assignment is to create a class named Currency, using integers as the primitive type for dollars. And I must use these public methods I have..... Now I removed the "cents" part, and the "subtration" part, because I'm assuming I can do those once I figure out how to do "Addition" for "Dollars" currency type.</p> <p>No matter what I put into the "Currency Add(int Dollars);" I cannot get my code to work =. I've done things like totalDollars += Dollars, return totalDollars, or just Dollars += Dollars, etc.</p> <p>The output is always garbage : "-8353513636". Or sometimes whatever number I put in the constructor.</p> <p>I just can not seem to get it to PASS the number in and keep it there (Eventually want to make it hold a running total), and output it when I'm done. I've shortened up my code because the only problem with my code is the parts dealing with the "class"/currency data type. It just won't work.</p> <p>At one point it told me it cannot convert from int to Currency data type</p> <p>Here's the code I have so far:</p> <pre><code>/* Program By: Date: 4/29/2011 Class: */ #include &lt;iostream&gt; #include &lt;iomanip&gt; #include &lt;fstream&gt; #include &lt;cstring&gt; #include &lt;cstdlib&gt; #include &lt;cctype&gt; #include &lt;cmath&gt; #include &lt;ostream&gt; using namespace std; // Currency Class class Currency { private: int Dollars; public: Currency(); Currency(int Dollars); Currency Add(int Dollars); int GetDollars(); }; Currency::Currency() { Dollars = 0; } Currency::Currency(int Dollars) { } // Add Currency Currency::Add(int Dollars) { // Have put totalDollars += Dollars, etc. // Have also put a "return" value here. } int Currency::GetDollars() { return Dollars; } int main() { Currency payroll; int currDollars; cout &lt;&lt; "Please enter a dollar mount" &lt;&lt; endl; cin &gt;&gt; currDollars; payroll.Add(currDollars); cout &lt;&lt; "Current Amount is: " &lt;&lt; payroll.GetDollars() &lt;&lt; endl; return 0; } </code></pre> <p>What am I doing wrong? I've been at this for several hours and I need to have it in by tomorrow =. Help MUCH APPRECIATED!!!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload