在其他人的帮助下,我从头开始重新编写代码,因为他们指出了许多错误和无法正常工作的事情。因此,我已经大量更改了代码。
除了两个我不知道如何开始工作的格式设置之外,我的程序还在工作。
我只需要在输出顶部打印一次“DAILY SCOOP REPORT”,但我已经移动了它,但由于数组的设置方式,我不知道把它放在哪里。
这是我的代码:
#include <iostream>
包括
包括
包括
包括
包括
使用命名空间标准;
int main() { 字符串风味输入,大写;字符串风味[] = {“巧克力”、“香草”、“草莓”、“薄荷”、“洛基路”、“摩卡”};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;
}
再次感谢所有的帮助。非常感谢。
感谢所有的帮助并为我指明了学习的方向,除了最后一部分之外,我已经完成了该计划。
当我移动“每日独家报道”行时,我明白了为什么它不起作用。我已经重命名了文件,当我编译它时,它正在输出“最后的工作配置”,如果这有意义的话。所以我创建了一个新项目(.cpp 文件必须有一个特定的名称才能提交)并将代码放入其中。现在该行只打印一次。
在下面的代码块中,我有它降低所有其他字母的大小写,而不是第一个左右它似乎正在做的事情。我之所以按照我的方式编码案例是因为说明希望风味报告打印出每个单词大写的第一个字母,然后再降低。我将研究如何在 Rocky Road 中设置第二个“R”,但除了忽略空白之外,我真的不知道如何。我需要解析行吗?
任何能指出我正确方向的人将不胜感激。
我试过了,但它在第一个 if 语句“语法错误:标识符'flavor_input'”中给出了错误。
//converting the first letter of input to uppercase if not already.
string::iterator it(flavor_input.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);
}