2014-02-08 24 views
0

所以下面的代碼工作正常,但有一個例外:運輸及工務局局長()在C++中沒有響應,如我所料

#include <iostream> 
#include <cmath> 
#include <iomanip> 
using namespace std; 


int main() 
{ 
    int value1, value2, value3, value4; 
    float calcMean,calcStDev; 


    // Input values from keyboard 
     // prompt user for input 
    cout << "Enter 1st value. " << endl; 
    cin >> value1; 
    cout << "Enter 2nd value. " << endl; 
    cin >> value2; 
    cout << "Enter 3rd value. " << endl; 
    cin >> value3; 
    cout << "Enter 4th value. " << endl; 
    cin >> value4; 

    // Calculate the mean, mean = (value1 + value2 + value3 + value4)/4.0 
    calcMean = (value1 + value2 + value3 + value4)/4.0; 

    // Calculate the standard deviation, standard deviation = squareroot((sum((input value-mean)*(input value-mean)))/number of input value - 1) 
    calcStDev = sqrt((pow((value1 - calcMean),2) + pow((value2 - calcMean),2) + pow((value3 - calcMean),2) + pow((value4 - calcMean),2))/(4-1)); 
     // Output display 
    cout << fixed << setprecision(2) << endl; 
    cout << "Mean of the four values:    " << setw(10) << calcMean << endl; 
    cout << "Standard deviation of the four values: " << setw(10) << calcStDev << endl; 

    cin.get(); 
    cin.get(); 
    return 0; 
} 

似乎輸出不被響應運輸及工務局局長()像我預期(我希望數字18.50直接超過19.64,一個在另一個之上)。

任何想法,我做錯了什麼?:

Enter 1st value. 
2 
Enter 2nd value. 
36 
Enter 3rd value. 
35 
Enter 4th value. 
1 

Mean of the four values:          18.50 
Standard deviation of the four values:  19.64 
+0

這裏它的工作原理,都使用g ++ 4.8.1和clang 3.4。 – Svalorzen

+0

請記錄你使用的文本編輯器,我們將要避免這樣一個令人難以置信的邪惡的。 –

+0

@Hans Passant例如MS VS代碼編輯器。:) –

回答

1

我覺得現在的問題是,字符串字面"Mean of the four values: "包含嵌入的製表符。可能會插入您按TAB鍵而不是SPACEBAR鍵的空格。

相關問題