Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,986 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,409 people online right now. Registration is fast and FREE... Join Now!




Pennies for Pay

 
Reply to this topicStart new topic

Pennies for Pay

supercharged_V6
1 Dec, 2006 - 02:34 PM
Post #1

D.I.C Head
**

Joined: 3 Oct, 2006
Posts: 57


My Contributions
Hi,

I basically have this down, i just need to know, how to add up all the pennies and convert them into dollars, for example, i would have 300 pennies, so how would i convert them into dollars by itself? i am totally confused and the book aint helping out much.

CODE

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int numDays, count, numPay;
    float total = 0.0;
    
    cout<< " Enter Number Of Days Worked\n";
    cin>>numDays;
    
    numPay++;
    count = 1;
    
    while (count<=numDays)
    {
          
          
          cout<<"\nDays "<< count <<endl;
          cout<<"pay :"<< numPay <<endl;
          //numPay++;?
          //total = numPay;
          numPay = numPay + numPay;
          total = numPay;
          count++;
          //++numPay;
          }
          cout<<" total pay is " << total<< endl;
          system ("pause");
          return 0;
          }



User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Pennies For Pay
1 Dec, 2006 - 02:37 PM
Post #2

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,276



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
I'm not sure I understand your question... but to find out how many dollars you have based on pennies... you would divide by 100.


But I imagine you are asking something more....
User is online!Profile CardPM
+Quote Post

ifoam
RE: Pennies For Pay
1 Dec, 2006 - 02:45 PM
Post #3

D.I.C Head
**

Joined: 26 Oct, 2006
Posts: 54



Thanked: 1 times
My Contributions
CODE
int main(int argc, char *argv[])
{
  int pennies = 356;
  int dollars, cents;

  dollars = pennies / 100;
  cents = pennies % 100;

  cout << dollars << " dollar(s) and " << cents << " cents.";
}


This post has been edited by ifoam: 1 Dec, 2006 - 02:45 PM
User is offlineProfile CardPM
+Quote Post

wreckingcru
RE: Pennies For Pay
1 Dec, 2006 - 11:31 PM
Post #4

New D.I.C Head
*

Joined: 20 Oct, 2006
Posts: 4


My Contributions
well, first mistake i can see is incrementing numPay (numPay++) before you initialize it!!

since numPay is never set to 0, when you start ++-ing it, it's holding garbage value. This will not give you a compilation error in c++ (it will in C)
User is offlineProfile CardPM
+Quote Post

supercharged_V6
RE: Pennies For Pay
2 Dec, 2006 - 12:21 AM
Post #5

D.I.C Head
**

Joined: 3 Oct, 2006
Posts: 57


My Contributions
QUOTE(wreckingcru @ 2 Dec, 2006 - 12:31 AM) *

well, first mistake i can see is incrementing numPay (numPay++) before you initialize it!!

since numPay is never set to 0, when you start ++-ing it, it's holding garbage value. This will not give you a compilation error in c++ (it will in C)


okay ive gone ahead and fixed all that.... i was able to figure it out... thanks for your help dudes...
User is offlineProfile CardPM
+Quote Post

supercharged_V6
RE: Pennies For Pay
2 Dec, 2006 - 12:28 AM
Post #6

D.I.C Head
**

Joined: 3 Oct, 2006
Posts: 57


My Contributions
here is the updated code

CODE

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    int numDays, count;
    float numPay = 1;
    float total = 0.0;
    cout<<    "-=|[Pennies For Pay]|=-"<<endl;
    cout<<" "<<endl;
    cout<< "Please Enter The Number Of Days Worked\n";
    cin>>numDays;
    count = 1;
    cout<<" "<<endl;
    cout<<"Day"<<"\t\t"<<"Amount Earned"<<endl;
    cout<<"----------------------------"<<endl;
    
    while (count<=numDays)
    {
          cout<<" "<<endl;
          
          
          cout<< count <<"\t\t\t"<< numPay <<endl;
          //cout<<"pay :"<< numPay <<endl;
          numPay = numPay + numPay;
          total = numPay / 100.0;
          count++;
          }
          cout<<" "<<endl;
          cout<< fixed << showpoint << setprecision(2);
          cout<<" Total Amount To Be Paid Is $"<<"\t"<< total << endl;
          cout<<" "<<endl;
          cout<<"-=|[Jonathan Robles]|=-"<<endl;
          system ("pause");
          return 0;
          }

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 07:34PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month