Help with formatting numbers

i need help trying to figure out how to get rid of zeros at the end of

Page 1 of 1

2 Replies - 524 Views - Last Post: 08 October 2008 - 01:22 PM Rate Topic: -----

#1 Zerobu  Icon User is offline

  • Black Hatter

Reputation: 13
  • View blog
  • Posts: 1,822
  • Joined: 14-January 08

Help with formatting numbers

Post icon  Posted 08 October 2008 - 10:41 AM

Here is my code, I want to know if i can get rid of all zeros at the end of my output.

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



void DrawBox(int rows, int cols, char symbol)
{
	int r, c;

	for(r=1; r<= rows; r++)
	{
		for(c=1; c<=cols; c++)
			cout<<symbol;

		cout<<endl;

	}
}
double  Power(int num,  double pow)
{
	int i;
	double  answer=1;

	

	for(i =0; i<pow; i++)	
		answer*=num;
	



	return answer; 
}

void main()
{
	int rows;
	int cols;
	int num;
	 double  pow;
	char symbol;

	cout<<"How many rows would you like? ";
	cin>>rows;
	cout<<"How many columns would you like? ";
	cin>> cols;
	cout<< "What type of symbol do you want? ";
	cin>> symbol;

	DrawBox(rows, cols, symbol);

	cout<<endl;

	cout<<"Give a number: ";
	cin>> num;
	cout<<"What power would you want to raise that number: ";
	cin>>pow;

	
	pow =Power(num, pow);

	cout<<fixed<<pow<<endl;

}



Is This A Good Question/Topic? 0
  • +

Replies To: Help with formatting numbers

#2 overlord_shimra  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 22
  • Joined: 07-October 08

Re: Help with formatting numbers

Posted 08 October 2008 - 11:48 AM

what is the output there.
Was This Post Helpful? 0
  • +
  • -

#3 Alianin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 07-October 08

Re: Help with formatting numbers

Posted 08 October 2008 - 01:22 PM

Have you tried using setprecision(x) yet? X meaning the number of decimal places you would like to display. So your code would look like:

	cout<<fixed<<setprecision(0)<<pow<<endl;



if you wanted no 0's to display.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1