Public feed #724681

Untitled

public text v1 · immutable
Raw Edit
·published 2007-10-03 19:51 UTC
rendered paste body
/* DisplayFormatted, Monday September 17th 2007 */

#include <iostream.h>
#include <math.h>

void DisplayFormatted (int n, int Width)
/*	Displays the value of n left-aligned in a field of size Width
 *	Post: Value displayed left-aligned in a field of size Width */
{
	cout << n;
	while (Width > n) {
		cout << " ";
		Width--;
	}
	cout << endl;
}

void DisplayFormatted (double n, int Width, int Decimals)
/*	Displays the value of n left-aligned in a field of size Width
 *	Post: Value displayed left-aligned in a field of size Width */
{
	cout << n << endl;
	cout << (n*long(pow(10, Decimals))) << endl;
	long nmod = (n*pow(10, Decimals));
	int counter = Decimals;
//	cout << (nmod - nmod%long(pow(10, counter))) << endl;
	cout << (nmod - (nmod%long(pow(10, counter)))) << endl;	
/*	while ((nmod - (nmod%long(pow(10, counter)))) > long(0)) {
		cout << 0;
		counter--;
	}*/
	//cout << pow(10, Decimals) << endl;
}
/*{
	cout << n;
	if (Width > (n+1)) {
		cout << ".";
		Width--;
		while (Width > n) {
			cout << 0;
			Width--;
		}
	}
	cout << endl;
}*/


int main()
{
	DisplayFormatted(1, 2);
	DisplayFormatted(1.22, 4, 4);
	return(0);
}