他の人の助けを借りて、コードをゼロからやり直しました。これは、多数のエラーや機能しないものを指摘したためです。したがって、コードを大幅に変更しました。
2 つの書式設定以外はプログラムを動作させていますが、動作する方法がわかりません。
出力の上部に「DAILY SCOOP REPORT」を 1 回だけ印刷する必要がありますが、移動しましたが、配列の設定方法が原因で、どこに配置すればよいかわかりません。
これが私のコードです:
#include <iostream>
含む
含む
含む
含む
含む
名前空間 std を使用します。
int main() {文字列flavor_input、Capitalize; string フレーバー[] = { "チョコレート"、"バニラ"、"ストロベリー"、"ミント"、"ロッキー ロード"、"モカ" }; int scoop_count [6] = { 0, 0, 0, 0, 0, 0}, スクープ = 0, j, k;
bool valid_option;
cout << "Welcome to Frozen Tongue Ice Cream Shop\n"<<endl;
cout << "Flavors avaliable: "<<endl;
cout << "Chocolate "<<endl;
cout << "Valnilla "<<endl;
cout << "Strawberry "<<endl;
cout << "Mint "<<endl;
cout << "Rocky Road "<<endl;
cout << "Mocha \n"<<endl;
while(true) {
cout << "Please enter the flavor of icecream sold or 'STOP' to exit.\n"<<endl;
getline (cin, flavor_input); // getline causes rocky road to be accepted with a space between the words.
string::iterator it( flavor_input.begin()); //converting the first letter of input to uppercase if not already.
if (it != flavor_input.end())
flavor_input[0] = toupper((unsigned char)flavor_input[0]);
while(++it != flavor_input.end())
{
*it = tolower((unsigned char)*it);
}
if (flavor_input == "STOP" || flavor_input == "Stop")
break;
valid_option = false;
for(int i=0;i<6;i++) //Checks to see if input matches those of possible inputs.
if(!flavor_input.compare(flavors[i]))
{
valid_option = true;
break;
}
if(!valid_option)
{
cout << "Invalid Flavor. Try again.\n\n";
flavor_input.clear();
continue;
}
for(int i=0;i<6;i++)
{
if(!flavor_input.compare(flavors[i]))
{
cout << "Enter how many scoops were sold: ";
cin >> scoops;
cin.ignore();
scoop_count[i] += scoops;
scoops = 0;
cout << '\n';
break;
}
}
}
for(int i=0;i<6;i++)
{
if(!scoop_count[i])
continue;
else
{
cout << "\nDAILY SCOOP REPORT: "<<endl;
cout << setiosflags( ios::left )
<< setw( 11 ) << flavors[i]
<< resetiosflags( ios::left )
<< setw( 4 ) << scoop_count[i] << endl;
}
}
cin.get();
return 0;
}
すべての支援に感謝します。大変感謝しております。
すべての支援と勉強の方向性を教えてくれたおかげで、最後の部分を除いてプログラムを完了できました。
「DAILY SCOOP REPORT」の行を移動したときに、なぜ機能しないのかがわかりました。私はファイルの名前を変更し、それをコンパイルすると、それが意味をなす場合、「最後の作業構成」のようなものを出力していました。そこで、新しいプロジェクトを作成し (.cpp ファイルには提出用の特定の名前が必要です)、コードを入れました。これで、行は一度だけ印刷されます。
以下のコードブロックでは、最初の文字以外のすべての文字の大文字と小文字を区別しているように見えます。私がこのようにケースコーディングを行っている理由は、各単語の最初の文字が大文字で、その後は小文字でフレーバーレポートが印刷されるように指示されているためです。Rocky Road で 2 番目の「R」をキャップする方法を調べますが、空白を無視する以外は、方法がよくわかりません。行を解析する必要がありますか?
私を正しい方向に向けてくれる人は誰でも大歓迎です。
試してみましたが、最初のifステートメントで「構文エラー:識別子 'flavor_input'」というエラーが発生します。
//converting the first letter of input to uppercase if not already.
string::iterator it( フレーバー入力.begin());
if flavor_input = "rocky road"
(it != flavor_input.end())
flavor_input[6] = toupper((unsigned char)flavor_input[6]);
if (it != flavor_input.end())
flavor_input[0] = toupper((unsigned char)flavor_input[0]);
while(++it != flavor_input.end())
{
*it = tolower((unsigned char)*it);
}