作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是一个相当弱的程序员,并得到了以下信息。我设置了语句,我可以在完成后清理它,但是例如,当用户输入“6”时,它将遍历第 1 节到第 6 节。
#include<iostream>
using namespace std;
int main()
{
int input;
cout << "Please enter a number from 1-12, USE '999' to close." << endl;
cin >> input;
for (int input = 1; input <= 12; input++)
{
if (input == 1)
{
cout << "\nOn the 1st day of Christmas my true love gave to me,\n A Partridge in a Pear Tree." << endl;
}
else if (input == 2)
{
cout << "\nOn the 2nd day of Christmas my true love gave to me :\nTwo Turtle Doves,\n And a Partridge in a Pear Tree." << endl;
}
else if (input == 3)
{
cout << "\n\nOn the 3rd day of Christmas my true love gave to me,";
cout << "Three French Hens\nTwo Turtle Doves,\nAnd a Partridge in a Pear Tree." << endl;
}
else if (input == 4)
{
cout << "\n\nOn the fourth day of Christmas my true love sent to me :\n";
cout << "four Calling Birds\n3 French Hens\n2 Turtle Doves\nand a Partridge in a Pear Tree" << endl;
}
else if (input == 5)
{
cout << "\n\nOn the fifth day of Christmas my true love sent to me:\n";
cout << " FIVE GOLDEN RINGS!, Four Calling Birds, three French Hens, 2 turtle doves\n";
cout << "And a partridge in a pear tree.";
}
else if (input == 6)
{
cout << "\n\nOn the sixth day of Christmas my true love sent to me :\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves\nand a Partridge in a Pear Tree\n";
}
else if (input == 7)
{
cout << "\n\nOn the seventh day of Christmas my true love sent to me :\n7 swans are swimming,\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves\nand a Partridge in a Pear Tree\n";
}
else if (input == 8)
{
cout << "\n\nOn the eigth day of Christmas my true love sent to me :\n8 maids are milking,\n7 swans are swimming,\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves\nand a Partridge in a Pear Tree\n";
}
else if (input == 9)
{
cout << "\n\nOn the nineth day of Christmas my true love sent to me :\n9 ladies dancing,\n8 maids are milking,\n7 swans are swimming,\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves \nand a Partridge in a Pear Tree\n";
}
else if (input == 10)
{
cout << "\n\nOn the tenth day of Christmas my true love sent to me :\n10 lords a leaping,\n9 ladies dancing,\n8 maids are milking,\n7 swans are swimming,\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves \n and a Partridge in a Pear Tree\n";
}
else if (input == 11)
{
cout << "\n\nOn the eleventh day of Christmas my true love sent to me :\n11 Pipers piping,\n10 lords a leaping,\n9 ladies dancing,\n8 maids are milking,\n7 swans are swimming,\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves \nand a Partridge in a Pear Tree\n";
}
else if (input == 12)
{
cout << "\n\nOn the twevle day of Christmas my true love sent to me :\n12 Drummers Drumming,\n11 Pipers piping,\n10 lords a leaping,\n9 ladies dancing,\n8 maids are milking,\n7 swans are swimming,\n6 Geese a Laying\n5 Golden Rings\n4 Calling Birds\n3 French Hens\n2 Turtle Doves\n and a Partridge in a Pear Tree\n";
}
else if (input == 999)
{
cout << "Thanks, Good bye!";
return 0;
}
else
{
cout << "Terminating program";
return 0;
}
}
system("pause");
return 0;
}
谢谢大家
最佳答案
改变for循环中的变量。当用户对输入变量进行输入时,您输入的变量在for循环中发生了变化,所以只需使用其他变量
int main()
{
int input;
cout << "Please enter a number from 1-12, USE '999' to close." << endl;
cin >> input;
for (int x = 1; x <= 12; x++)
{
// bla bla bla
关于c++ - 圣诞节 12 天,不循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27486697/
开始我以为悬浮窗口,可以用Android中得PopupWindow 来实现,虽然也实现了,但局限性非常大。比如PopupWindow必须要有载体View,也就是说,必须要指定在那个View的上面来实
我是一个相当弱的程序员,并得到了以下信息。我设置了语句,我可以在完成后清理它,但是例如,当用户输入“6”时,它将遍历第 1 节到第 6 节。 #include using namespace std;
我是一名优秀的程序员,十分优秀!