有人能告訴我,我做錯了什麼我已經盡了全力用此程序,請與人在他們的手上多一點時間,讓他們可以花時間看節目和幫助!謝謝大家的時間:)C++編程的問題
#include <iostream>
#include <string>
#include <cctype>
using std::cout;
using std::cin;
using std::endl;
//function prototypes
void getItemNumber();
void checkItemNumber (char *, int);
int main()
{
//declare variables
string Item = "";
getItemNumber();
checkItemNumber(item);
//call function to get input
//void getItemNumber();
//void checkItemNumber (item);
cout << "Enter your 5-digit item #: ";
cin >> item;
while (item.length() != 5)
{
cout << "Invalid item #. Please enter a 5-digit item # ";
getline(cin, item);
}
if (item.length() == 5)
{
if ('B' == toupper(item[2]))
cout << "Your color is blue" << endl;
else if ('G' == toupper(item[2]))
cout << "Your color is green" << endl;
else if ('R' == toupper(item[2]))
cout << "Your color is red" << endl;
else if ('W' == toupper(item[2]))
cout << "Your color is white" << endl;
}
else
cout<< "Invalid name no matching color...";
// if code is not from any of the above.
system("pause");
return 0;
}
爲什麼我的代碼在我輸入正確的時候混亂了? – Rosemary 2009-11-25 01:32:48
使用詳細模式,在這裏,我會給你一個手... – 2009-11-25 01:33:56
因爲代碼應該縮進四個空格。 – 2009-11-25 01:34:04