6 Replies - 7578 Views - Last Post: 13 August 2009 - 11:35 PM Rate Topic: -----

#1 supercharged_V6  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 03-October 06

Pennies for Pay

Posted 01 December 2006 - 03:34 PM

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.

#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;
		  }



Is This A Good Question/Topic? 0
  • +

Replies To: Pennies for Pay

#2 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1858
  • View blog
  • Posts: 20,275
  • Joined: 17-March 01

Re: Pennies for Pay

Posted 01 December 2006 - 03:37 PM

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....
Was This Post Helpful? 0
  • +
  • -

#3 ifoam  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 54
  • Joined: 26-October 06

Re: Pennies for Pay

Posted 01 December 2006 - 03:45 PM

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: 01 December 2006 - 03:45 PM

Was This Post Helpful? 0
  • +
  • -

#4 wreckingcru  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 20-October 06

Re: Pennies for Pay

Posted 02 December 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)
Was This Post Helpful? 0
  • +
  • -

#5 supercharged_V6  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 03-October 06

Re: Pennies for Pay

Posted 02 December 2006 - 01:21 AM

View Postwreckingcru, on 2 Dec, 2006 - 12:31 AM, said:

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...
Was This Post Helpful? 0
  • +
  • -

#6 supercharged_V6  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 1
  • View blog
  • Posts: 57
  • Joined: 03-October 06

Re: Pennies for Pay

Posted 02 December 2006 - 01:28 AM

here is the updated 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;
		  }


Was This Post Helpful? 1
  • +
  • -

#7 AJOHNZ  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 82
  • Joined: 10-May 09

Re: Pennies for Pay

Posted 13 August 2009 - 11:35 PM

i just was practicing this problem in starting out with c++ with tony gaddis. here is how i wrote the code i thought it was interesting to look at our different styles.

#include <iostream>
using namespace std;

int main()
{
	int days;
	double final = 1;
	double total = 0.00;
	cout << "Enter the number of days: ";
	cin >> days;

	for (int i = 1; i < (days + 1); i++)
	{
		cout << "Day " << i << ": " << '\t' << "$" << final/100 << endl;
		total += final;
		final += final;
	}

	cout << "Total: " << '\t' << "$" << total/100 << endl;
	return 0;
}


This post has been edited by AJOHNZ: 13 August 2009 - 11:36 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1