我需要絕望的幫助,因爲我無法弄清楚爲什麼和我做錯了什麼。我試圖向用戶詢問關於長度轉換的多個問題。我遇到了一個問題,只有第一個問題被問到,而下一個問題沒有機會被問到。我試過兩個版本,但都是有缺陷的。我很難調試很長的編譯時間和多用戶輸入要求
Sisestage pikkus meetrides:
500
Sisestage uue uhiku kood (alj, ver, kyn, toll, jalg, jard, lii):
Sisestasite vale vaartuse:500 void vale uhiku:
我的代碼:
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
using namespace std;
int main()
{
float P; /* Pikkus meetrites */ /*Length P in metres*/
string U; /* M66du:hik*/ /* Unit of measure*/
float ALJ;
float VER;
float KYN;
float TOLL;
float JALG;
float JARD;
float LII;
do
{
cout<<"Sisestage pikkus meetrides: \n"; /*Ku:sin kasutajalt pikkust P*/ /* Asking user for the length P in metres*/
cin>>P;
if (P > 0)
cout<<"Sisestage uue uhiku kood (alj, ver, kyn, toll, jalg, jard, lii): \n"; /* Ku:sin kasutajalt u:hiku koodi U*/ /* Asking user for the length U in metres*/
getline(cin, U);
} while (P > 0);
cout << "Sisestasite vale vaartuse:"<<P<< endl; /*Veateade*/
ALJ = P/5572;
VER = P/1066.781;
KYN = P/0.53;
TOLL = P/0.0254;
JALG = P/0.3048;
JARD = P/0.9144;
LII = P/500;
if(U == "alj")
{
cout<< setprecision(2)<<fixed<< P <<"m = "<< ALJ << U <<"." ;
}
else if(U == "ver")
{
cout<< setprecision(2) << fixed << P <<" m ="<< VER << U <<".";
}
else if(U == "kyn")
{
cout<< setprecision(2) << fixed << P <<" m ="<< KYN << U <<".";
}
else if(U == "toll")
{
cout<< setprecision(2) << fixed << P <<" m ="<< TOLL << U <<".";
}
else if(U == "jalg")
{
cout<< setprecision(2) << fixed << P<<" m ="<< JALG << U <<".";
}
else if(U == "jard")
{
cout<< setprecision(2) << fixed << P <<" m ="<< JARD << U <<".";
}
else if(U == "lii")
{
cout<< setprecision(2) << fixed << P <<" m ="<< LII << U <<".";
}
getchar();
getchar();
}
我完全不理解你的問題標題。 –
「我很難調試需要多個用戶輸入實例的程序,這部分是因爲編譯時間太長。 – Kevin
@Kevin:的確,但上面的代碼應該沒有時間去編譯! –