944,080 Members | Top Members by Rank

Ad:
  • C++ Code Snippet
  • Views: 1371
  • C++ RSS
1

Byte to KILOBYTE conversion in c++

by on Oct 15th, 2009
HEy
Buddies in early morning i want to calculate that exchange during download & you very well known that it is shown in byte so just i am g with c++ and play a game for writing this.
thanks
enjoy it.
It's very easy and handy with simple logic.
C++ Code Snippet (Toggle Plain Text)
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.  
  8. long double byte;
  9. long double kilobyte;
  10. long double megabyte;
  11. long double gigabyte;
  12.  
  13.  
  14. cout << "Enter the byte value";
  15. cin>>byte;
  16.  
  17. kilobyte = byte / 1024;
  18. megabyte = kilobyte / 1024;
  19. gigabyte = megabyte / 1024;
  20.  
  21.  
  22.  
  23. cout << byte << " Equal to " << kilobyte << " Kilobyte's "<<"\n";
  24.  
  25.  
  26. cout << byte << " Equal to " << megabyte << " Megabyte's "<<"\n";
  27.  
  28.  
  29. cout << byte << " Equal to " << gigabyte << " Gigabyte's "<<"\n";
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36. system("pause");
  37. return 0;
  38. }
Comments on this Code Snippet
Oct 15th, 2009
1

Re: Byte to KILOBYTE conversion in c++

Nice it only has two flaws.
Change the system("pause") to cin.get();
And put a while loop around it all so you can do it repeated times.


//K0s3rv
Junior Poster in Training
K0ns3rv is offline Offline
86 posts
since Oct 2009
Oct 15th, 2009
0

Re: Byte to KILOBYTE conversion in c++

thanks for your comment
Light Poster
nandux8 is offline Offline
31 posts
since Sep 2008
Oct 15th, 2009
1

Re: Byte to KILOBYTE conversion in c++

Nice code, good for beginners to understand and get a foot on c++.
u did good,nandux8.
Posting Whiz in Training
tkud is offline Offline
235 posts
since Sep 2009
Message:
Previous Thread in C++ Forum Timeline: could I use C++ to implemant this software ?
Next Thread in C++ Forum Timeline: Read windows registry in c??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC