試圖將(回)C++並通過書中的練習,我得到一個奇怪的錯誤。添加簡單的cout後,程序不會運行
使用代碼::塊+ GCC
這是當前程序。
#include "std_lib_facilities.h";
int main()
{
double val, smallest = 9999, largest = 0;
string strunit;
for (int i = 0; i < 10; i++) {
cout << "Enter value: ";
cin >> val >> strunit;
if (strunit == "in") {
val = val*0.254;
} else if (strunit == "cm") {
val = val/100;
}
if (val > largest) {
largest = val;
} else if (val < smallest) {
smallest = val;
}
cout << "Largest: " << largest << "smallest: " << smallest << endl;
}
return 0;
}
我打算使用while循環,但現在它是一個for。但結果是一樣的。
這是構建結果:
-------------- Build: Debug in drill_4 (compiler: GNU GCC Compiler)---------------
mingw32-g++.exe -o bin\Debug\drill_4.exe obj\Debug\exe\principles_and_practices\drill_4\main.o
Process terminated with status 0 (0 minute(s), 0 second(s))
0 error(s), 0 warning(s) (0 minute(s), 0 second(s))
的IDE聲稱該計劃尚未建成,並要求我重建。
如果我註釋掉程序將運行的幾乎任何行。
我最初使用了一行if語句,結果相同。
我對IDE也很陌生,所以不確定在哪裏可以找到我需要的所有信息,但我想pgrogram鏈接不正確?
任何想法我做錯了什麼?
你可以嘗試從命令行運行gcc,而無需通過CodeBlocks? – Beta
這是完整的代碼..我不知道在這裏做什麼「std_lib_facilities.h」,但是當我運行這個代碼時,包括這就是沒有問題的運行.. –
mhs