gpt4 book ai didi

C++ 完全跳过一个开关

转载 作者:太空宇宙 更新时间:2023-11-04 15:59:05 26 4
gpt4 key购买 nike

我必须为我的计算机科学课编写一个简单的程序,我的老师要我使用循环和开关打印出十二天的圣诞歌曲,我正在尝试运行这段代码,但开关被跳过了完全地。如果你能帮助我,那就太好了,谢谢!

#include <iostream>
using namespace std;
int main()
{
for (int i = 12; i > 0; i--)
{
cout << "On the " << i << " day of Christmas my true love gave to me, \n";
switch (i)
{
case 1: "Twelve drummers drumming\n";
case 2: "Eleven pipers piping\n";
case 3: "Ten lords a-leaping\n";
case 4: "Nine ladies dancingn";
case 5: "Eight maids a-milking\n";
case 6: "Seven swans a-swimming\n";
case 7: "Six geese a-laying\n";
case 8: "Five gold rings\n";
case 9: "Four colly birds\n";
case 10: "Three french hens\n";
case 11: "Two turtle doves, and\n";
case 12: "A partridge in a pear tree\n";
break;
}
}
system("pause");
return 0;
}

最佳答案

除了评估字符串文字(并丢弃该值)之外,您的 switch 没有任何事情。替换你的每个案例:

case X: std::cout << "the string...\n";

关于C++ 完全跳过一个开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48970300/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com