2014-05-01 129 views
0

我在做3列的表格Dec Okt Hex in C++。Dec十六進制表C++?

輸入應該是一個大於或等於1的整數,然後打印一個包含三列的表格,其中所有從1到十進制,八進制和十六進制數字的整數。

比如我們輸入的號碼輸出應該是這樣的:

這裏是我的代碼:

#include <cstdlib> 
#include <iostream> 

using namespace std; 

int main() 
{ 
     
     
   while (1) 
    { 
        int varde ; 
        cout << " Give the desired value (at least 1):"; 
        cin >> varde ; 
         
        if (varde <1) 
         { 
           cout << varde << "Invalid value , try again! Give the desired value for the table :"; 
         } 
          
         else 
         { 
             cout << " desired value " << varde << "\ n"; 

         } 
          
       
         
           

          for (int row = 0; row < varde ; + + row) 
               { 
                       for (int column = 0; columnIndex < 3; + + column) 
                            { 
                                std :: cout << std :: December << varde << '\ t '; 
                                std :: cout << std :: hex << varde << '\ t '; 
                                std :: cout << std :: oct << varde << '\ t '; 
                                 
  
                            } 
                       std :: cout << std :: endl; 
     
                } 
          
          
          
          
           
     } 
      
 } 

但我得到這樣的輸出:

https://s27.postimg.org/mj8kzppnn/up2_2.jpg

+4

你總是打印varde而不是currend值(row),而你的第二個for循環沒用,你用\ t一次顯示3個冒號 – Boo

回答

1

你想輸出row,你正在迭代的變量,而不是varde,所需的最大值,對不對?

std :: cout << std :: dec << row << '\ t '; 
std :: cout << std :: hex << row << '\ t '; 
std :: cout << std :: oct << row << '\ t ';