473,785 Members | 2,895 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting a decimal integer number to binary form

10 New Member
Hello,

I am receiving the following error: error C2065: 'to_binary' : undeclared identifier
while running the code below.

If anyone can help I'll appreciate it?

Thank you,
Tukeind

// File: fractal.cxx
// A demonstration program for the random_fractal function from Chapter 9.

#include <cassert> // Provides assert
#include <cstdlib> // Provides EXIT_SUCCESS
#include <iostream.h> // Provides cin, cout
#include "useful.h" // From Appendix H. Provides random_real, display
//using namespace std;

// PROTOTYPE for the function used in this demonstration program.
void random_fractal
(double left_height, double right_height, double width, double epsilon);
// Precondition: width and epsilon are both positive.
// Postcondition: The function has generated a random fractal from a line
// segment. The parameters left_height and right_height are the heights of the
// two endpoints of the line segment, and the parameter width is the segment's
// width. The generation of the random fractal stops when the width of the
// line segments reaches epsilon or less.
// Method of displaying the output: The height of the right endpoint of
// each line segment in the random fractal is displayed by calling the
// function display(...).

int main( )
{
cout << "The decimal number 10 equals ";
to_binary( 10 );
cout << " binary." << endl;

cout << "The decimal number 100 equals ";
to_binary( 100 );
cout << " binary." << endl;

cout << "The decimal number 1000 equals ";
to_binary( 1000 );
cout << " binary." << endl;

cout << "The decimal number 10000 equals ";
to_binary( 10000 );
cout << " binary." << endl;

return EXIT_SUCCESS;
}

void to_binary(int number)
{
if( number == 10)
return;

to_binary( number / 2);

cout << number % 2;
}
Apr 20 '07 #1
2 4503
gpraghuram
1,275 Recognized Expert Top Contributor
Hi,
You have to add the rprototype to the to_binary function before the main function.
Expand|Select|Wrap|Line Numbers
  1. #include <cassert> // Provides assert
  2. #include <cstdlib> // Provides EXIT_SUCCESS
  3. #include <iostream.h> // Provides cin, cout
  4. #include "useful.h" // From Appendix H. Provides random_real, display
  5. //using namespace std;
  6. void to_binary(int number);
  7. // PROTOTYPE for the function used in this demonstration program.
  8. void random_fractal
  9. (double left_height, double right_height, double width, double epsilon);
  10. // Precondition: width and epsilon are both positive.
  11. // Postcondition: The function has generated a random fractal from a line
  12. // segment. The parameters left_height and right_height are the heights of the
  13. // two endpoints of the line segment, and the parameter width is the segment's
  14. // width. The generation of the random fractal stops when the width of the
  15. // line segments reaches epsilon or less. 
  16. // Method of displaying the output: The height of the right endpoint of
  17. // each line segment in the random fractal is displayed by calling the
  18. // function display(...).
  19.  
  20. int main( )
  21. {
  22. cout << "The decimal number 10 equals ";
  23. to_binary( 10 );
  24. cout << " binary." << endl;
  25.  
  26. cout << "The decimal number 100 equals ";
  27. to_binary( 100 );
  28. cout << " binary." << endl;
  29.  
  30. cout << "The decimal number 1000 equals ";
  31. to_binary( 1000 );
  32. cout << " binary." << endl;
  33.  
  34. cout << "The decimal number 10000 equals ";
  35. to_binary( 10000 );
  36. cout << " binary." << endl;
  37.  
  38. return EXIT_SUCCESS;
  39. }
  40.  
  41. void to_binary(int number)
  42. {
  43. if( number == 10)
  44. return;
  45.  
  46. to_binary( number / 2);
  47.  
  48. cout << number % 2;
  49. }
  50.  
That will solve the issue.
Thanks
Raghuram
Apr 20 '07 #2
Tukeind
10 New Member
Thank you that worked...earlie r i had void to_binary(int) as my prototype
...should had written it like you have it...Thanks a lot!!

Hi,
You have to add the rprototype to the to_binary function before the main function.
Expand|Select|Wrap|Line Numbers
  1. #include <cassert> // Provides assert
  2. #include <cstdlib> // Provides EXIT_SUCCESS
  3. #include <iostream.h> // Provides cin, cout
  4. #include "useful.h" // From Appendix H. Provides random_real, display
  5. //using namespace std;
  6. void to_binary(int number);
  7. // PROTOTYPE for the function used in this demonstration program.
  8. void random_fractal
  9. (double left_height, double right_height, double width, double epsilon);
  10. // Precondition: width and epsilon are both positive.
  11. // Postcondition: The function has generated a random fractal from a line
  12. // segment. The parameters left_height and right_height are the heights of the
  13. // two endpoints of the line segment, and the parameter width is the segment's
  14. // width. The generation of the random fractal stops when the width of the
  15. // line segments reaches epsilon or less. 
  16. // Method of displaying the output: The height of the right endpoint of
  17. // each line segment in the random fractal is displayed by calling the
  18. // function display(...).
  19.  
  20. int main( )
  21. {
  22. cout << "The decimal number 10 equals ";
  23. to_binary( 10 );
  24. cout << " binary." << endl;
  25.  
  26. cout << "The decimal number 100 equals ";
  27. to_binary( 100 );
  28. cout << " binary." << endl;
  29.  
  30. cout << "The decimal number 1000 equals ";
  31. to_binary( 1000 );
  32. cout << " binary." << endl;
  33.  
  34. cout << "The decimal number 10000 equals ";
  35. to_binary( 10000 );
  36. cout << " binary." << endl;
  37.  
  38. return EXIT_SUCCESS;
  39. }
  40.  
  41. void to_binary(int number)
  42. {
  43. if( number == 10)
  44. return;
  45.  
  46. to_binary( number / 2);
  47.  
  48. cout << number % 2;
  49. }
  50.  
That will solve the issue.
Thanks
Raghuram
Apr 20 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

21
4535
by: Batista, Facundo | last post by:
Here I send it. Suggestions and all kinds of recomendations are more than welcomed. If it all goes ok, it'll be a PEP when I finish writing/modifying the code. Thank you. .. Facundo
17
6153
by: John Bentley | last post by:
John Bentley: INTRO The phrase "decimal number" within a programming context is ambiguous. It could refer to the decimal datatype or the related but separate concept of a generic decimal number. "Decimal Number" sometimes serves to distinguish Base 10 numbers, eg "15", from Base 2 numbers, Eg "1111". At other times "Decimal Number" serves to differentiate a number from an integer. For the rest of this post I shall only use either...
2
7679
by: Mariusz Sakowski | last post by:
I'm writing class which will be able to store large numbers (my ambition is to make it able to operand on thousands of bits) and perform various operations on it (similiar to those available with int type). I want to store the number as binary stream, and I don't know how to convert large decimal string (char*) to binary stream. Converting using MOD would last for hours with really big numbers, and in fact I don't know any other ways to...
25
6752
by: TK | last post by:
I'm used to programming in c or c++ in which my problem is simple. I want to be able to enter a value on a page (like 3.2), and then read it as a 32-bit float and break it into it's individual bytes. I've tried using bitwise operators, but they seem to convert the value into an integer first, and i've tried using the toString() method to convert it into a hex value so i can parse it, but that also seems to first convert it into an...
18
26754
by: No Such Luck | last post by:
Hi all: I have an unsigned char array (size 4): unsigned char array; array = 0x00; array = 0x00; array = 0x02; array = 0xe7;
15
35515
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
28
5932
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly. See section 4.7 for Rounding issues.
0
3353
by: Terry Reedy | last post by:
A. Joseph wrote: These are number representation systems that can be applied to or used with integral, rational (numberator,denominator), and 'point' numbers. Try Wikipedia or any search engine. There are standard algorithms for converting between representations. See above. Good programmer calculators have these built in.
0
28070
Frinavale
by: Frinavale | last post by:
Convert a Hex number into a decimal number and a decimal number to Hex number This is a very simple script that converts decimal numbers into hex values and hex values into decimal numbers. The example following this one demonstrates how to convert decimal numbers into binary values. A hex number is a string that contains numbers between 0-9 and characters A-F; where A = 10, B = 11, ..., F = 15. (For more information please look up...
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10325
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10148
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9950
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8972
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6740
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3646
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.