Advertisement
Guest User

Untitled

a guest
Nov 30th, 2015
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #include<iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. double a;
  6. double b;
  7. double c[9];
  8. double data;
  9. int count;
  10. int remaining_digits;
  11. int divideby;
  12.  
  13.  
  14. int get_divideby(int count){
  15.  int output;
  16.  
  17.  switch(count){
  18.   case 0:
  19.    output = 1;
  20.     return output;
  21.     break;
  22.   case 1:
  23.   output = 10;
  24.     return output;
  25.     break;
  26.   case 2:
  27.   output = 100;
  28.      return output;
  29.     break;
  30.   case 3:
  31.   output = 1000;
  32.     return output;
  33.     break;
  34.   case 4:
  35.   output = 10000;
  36.     return output;
  37.     break;
  38.   case 5:
  39.   output = 100000;
  40.     return output;
  41.     break;
  42.   case 6:
  43.   output = 1000000;
  44.     return output;
  45.     break;
  46.   case 7:
  47.   output = 10000000;
  48.     return output;
  49.     break;
  50.   case 8:
  51.   output = 100000000;
  52.     return output;
  53.     break;
  54.   case 9:
  55.   output = 1000000000;
  56.     return output;
  57.     break;
  58.   }
  59.  }
  60.  
  61. int main(){
  62.  
  63.   cout << "Input 10 bit control code: ";
  64.   cin >> data;
  65.   cout <<  "Input 10 bit code: " << data;
  66.   count = 0;
  67.  
  68.    for (count; count<10; count++)
  69.  {
  70.  
  71.     divideby = get_divideby(count);
  72.  
  73.     cout << "\nInput Data: " << data << "(Double)\n";
  74.     cout << "Number = " << count << "\n";
  75.     cout << "Dividing By: " << divideby;
  76.      a = (data / divideby);
  77.        cout << "A Process: " << a << "\n";
  78.          b = fmod(a, 10); //Modulo cannot be used on doubles, so fmod is used instead.
  79.        cout << "B Process: " << b << "\n";
  80.      c[count]= floor(b); //Floor rounds the number down
  81.  
  82.        cout << "Final Output (C): " << c[count] << "\n";
  83.        cout << "------------------------------------------\n";
  84.  }
  85.  
  86.   if (count=9){ //Prints out array content
  87.    for (count; count>=0; count--)
  88.   {
  89.     cout << "Array " << count << " :" << c[count] << "\n";
  90.   }
  91.  }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement