Homework Help needed abut Rounding stuff

How to use round in c++ { Easy Way }

Page 1 of 1

9 Replies - 3186 Views - Last Post: 05 January 2007 - 11:06 AM Rate Topic: -----

#1 krunal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-January 07

Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 05:18 PM

thz is my code i dont why complier says

compiling...
2003 J2.cpp
C:\Documents and Settings\HP_Owner\Desktop\c++ programs\2003 J2.cpp(17) : error C2065: 'round' : undeclared identifier
Error executing cl.exe.

n how to use round in c++ .......



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


using namespace std;

int main()
{
	int a,l,w,b;

	do 
	{
		cout<<"Enter number of pictures :- ";
		cin>>a;

		l = round(sqrt(a));
		

		do
		{
			l--;
		}while((a%l) == 0);
		
		w = a / l;
		cout<<" Minimum perimeter is "<< ((2*l) + (2*w)) <<" with dimensions "<< w <<" X "<< l <<endl;

	}while (a==0);

	return 0;
}



thnxs for helping me out

This post has been edited by Dark_Nexus: 04 January 2007 - 08:15 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Homework Help needed abut Rounding stuff

#2 BitByte  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 194
  • Joined: 09-August 06

Re: Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 06:04 PM

Hey Krunal,

Nothing too serious, you are using round in your file:

 = round(sqrt(a));


but you have not declared it anywhere. Is it a double or int or char or something else? The compiler does not know what it is. And is that an 'i' you are using or an '|' ? When the compiler say's it's an undeclared identifier, it means you have not told the compiler what type the variable is. Give the variable a type name and a value ( even if it's zero ) and you should be fine.
Was This Post Helpful? 0
  • +
  • -

#3 krunal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-January 07

Re: Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 06:59 PM

View PostBitByte, on 4 Jan, 2007 - 06:04 PM, said:

Hey Krunal,

Nothing too serious, you are using round in your file:

 = round(sqrt(a));


but you have not declared it anywhere. Is it a double or int or char or something else? The compiler does not know what it is. And is that an 'i' you are using or an '|' ? When the compiler say's it's an undeclared identifier, it means you have not told the compiler what type the variable is. Give the variable a type name and a value ( even if it's zero ) and you should be fine.



vell i try

 = round(sqrt(a));


thz buh it doesnt work ......
Was This Post Helpful? 0
  • +
  • -

#4 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 07:24 PM

Both the sqrt() and round() functions take doubles as opposed to ints, but you appear to be suing them correctly aside from that. What compiler are you using? There are some compilers that will not have the round() function....
Was This Post Helpful? 0
  • +
  • -

#5 krunal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-January 07

Re: Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 07:53 PM

I m using Visual Basic c++ 6.0 ......
Was This Post Helpful? 0
  • +
  • -

#6 Xing  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 19
  • View blog
  • Posts: 725
  • Joined: 22-July 06

Re: Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 08:22 PM

View Postkrunal, on 5 Jan, 2007 - 08:23 AM, said:

I m using Visual Basic c++ 6.0 ......

Visual Basic and C++ are two different languages. I guess you meant Visual Studio 6.0
Was This Post Helpful? 0
  • +
  • -

#7 krunal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-January 07

Re: Homework Help needed abut Rounding stuff

Posted 04 January 2007 - 08:52 PM

oh yea Microsoft Visual C++ 6.0 .......
Was This Post Helpful? 0
  • +
  • -

#8 Manny  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 44
  • Joined: 30-May 06

Re: Homework Help needed abut Rounding stuff

Posted 05 January 2007 - 08:15 AM

View Postkrunal, on 4 Jan, 2007 - 08:52 PM, said:

int a,l,w,b;




And your professor is going to want see better variables names then

Int a, l, v, b;

You need some thing more meaningful variable names

that describe what they are for like

int num; or something like that.
Was This Post Helpful? 0
  • +
  • -

#9 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 250
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Homework Help needed abut Rounding stuff

Posted 05 January 2007 - 08:59 AM

The variable names do not account for the compilers failure to recognize the round function.
Was This Post Helpful? 0
  • +
  • -

#10 krunal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-January 07

Re: Homework Help needed abut Rounding stuff

Posted 05 January 2007 - 11:06 AM

nvm i got the answer for thz problem ......

thz is solution for the problem ......

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


using namespace std;

int main()
{
	int a,l,w;
	double b;

	do 
	{
		cout<<"Enter number of pictures :- ";
		cin>>a;

		b = sqrt(a);
		double z;
		z=b-((int)b);
		
		if(z!=0)
		{
			if(z>=0.5)
			{
				l=((int)b)+1;
			}
			else
			{
				l=(int)b;
			}
		 }
		 else 
		 {
			l=(int)b;
		 }

		while((a%l) != 0)
		{
			l--;
		}
		
		w = a / l;

		cout<<" Minimum perimeter is "<< ((2*l) + (2*w)) <<" with dimensions "<< w <<" X "<< l <<endl;

	}while (a==0);

	return 0;
}



This post has been edited by krunal: 05 January 2007 - 11:08 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1