473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Converting a decimal integer number to binary form

10
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 4476
gpraghuram
1,275 Expert 1GB
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
Thank you that worked...earlier 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
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
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....
2
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...
25
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...
18
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
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
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
0
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...
0
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.