Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;嵌套循环_C++_Loops_Nested - Fatal编程技术网

C++ C++;嵌套循环

C++ C++;嵌套循环,c++,loops,nested,C++,Loops,Nested,我在编写这个嵌套循环时遇到了很多麻烦 我们得数一数泡泡和它们各自的小玩意儿 我必须提示用户输入气泡数的整数。 并提示用户输入一个整数,表示每个气泡的饰品数量 每个泡泡都会说“水滴”! 每次泡沫过后,每个小玩意儿都会连续说“bloop!”,然后是一行新词 我的代码是: cout << "How many bubbles are there? "; cin >> bubbles; cout << "How many baubles are being create

我在编写这个嵌套循环时遇到了很多麻烦

我们得数一数泡泡和它们各自的小玩意儿

我必须提示用户输入气泡数的整数。 并提示用户输入一个整数,表示每个气泡的饰品数量

每个泡泡都会说“水滴”! 每次泡沫过后,每个小玩意儿都会连续说“bloop!”,然后是一行新词

我的代码是:

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles;


while (bubbles > 0) {
    cout << "BLOP!" << endl;
    bubbles--;
    for (baubles; baubles > 0; baubles--) {
        cout << "bloop!" << endl;
    }
}
应该是这样

BLOP!
bloop!
bloop!
BLOP!
bloop!
bloop!
BLOP!
bloop!
bloop!
BLOP!
bloop!
bloop!
感谢您的帮助。我尝试了许多循环方法,包括if语句,试图让它工作,但我似乎无法做到这一点

 for (baubles; baubles > 0; baubles--) 
应该是:

 for (baubles2 = baubles; baubles2 > 0; baubles2--) 
因为它每次都要重置。否则,在第一次迭代之后,它将永远保持为0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (int baubles_aux = baubles; baubles_aux > 0; baubles_aux--) {
        cout << "bloop!" << endl;

}
}
应该是:

 for (baubles2 = baubles; baubles2 > 0; baubles2--) 
因为它每次都要重置。否则,在第一次迭代之后,它将永远保持为0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (int baubles_aux = baubles; baubles_aux > 0; baubles_aux--) {
        cout << "bloop!" << endl;

}
}
应该是:

 for (baubles2 = baubles; baubles2 > 0; baubles2--) 
因为它每次都要重置。否则,在第一次迭代之后,它将永远保持为0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (int baubles_aux = baubles; baubles_aux > 0; baubles_aux--) {
        cout << "bloop!" << endl;

}
}
应该是:

 for (baubles2 = baubles; baubles2 > 0; baubles2--) 
因为它每次都要重置。否则,在第一次迭代之后,它将永远保持0;
cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (int baubles_aux = baubles; baubles_aux > 0; baubles_aux--) {
        cout << "bloop!" << endl;

}
}
小玩意; 而(气泡>0){ cout
cout>气泡;
小玩意;
而(气泡>0){
cout
cout>气泡;
小玩意;
而(气泡>0){
cout
cout>气泡;
小玩意;
而(气泡>0){

如果每次迭代
气泡
,您都需要将变量
baubles
重置为其原始值,请使用另一个变量
baubles0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles0;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (baubles = baubles0; baubles > 0; baubles--) {
    cout << "bloop!" << endl;

}
}
cout>气泡;
cout>baubles0;
而(气泡>0){

如果每次迭代
气泡
,您都需要将变量
baubles
重置为其原始值,请使用另一个变量
baubles0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles0;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (baubles = baubles0; baubles > 0; baubles--) {
    cout << "bloop!" << endl;

}
}
cout>气泡;
cout>baubles0;
而(气泡>0){

如果每次迭代
气泡
,您都需要将变量
baubles
重置为其原始值,请使用另一个变量
baubles0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles0;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (baubles = baubles0; baubles > 0; baubles--) {
    cout << "bloop!" << endl;

}
}
cout>气泡;
cout>baubles0;
而(气泡>0){

如果每次迭代
气泡
,您都需要将变量
baubles
重置为其原始值,请使用另一个变量
baubles0

cout << "How many bubbles are there? ";
cin >> bubbles;
cout << "How many baubles are being created by each bubble? ";
cin >> baubles0;


while (bubbles > 0) {
cout << "BLOP!" << endl;
bubbles--;
for (baubles = baubles0; baubles > 0; baubles--) {
    cout << "bloop!" << endl;

}
}
cout>气泡;
cout>baubles0;
而(气泡>0){

在外循环的一次迭代后,还剩下多少小玩意儿?你的代码中有没有补充小玩意儿的东西?剩下0个。没有,没有任何补充。下面的答案帮助我解决了这个问题。谢谢大家!在外循环的一次迭代后,还剩下多少小玩意儿?你的c代码中有什么吗补充饰品库存的ode?剩下0个。没有。没有任何补充。下面的答案帮助我解决了这个问题。谢谢大家!在外循环的一次迭代后还剩下多少饰品?你的代码中有什么补充饰品库存的吗?剩下0个。没有,没有任何补充成。下面的答案帮助我解决了这个问题。谢谢大家!在外循环的一次迭代后,还剩下多少小玩意儿?你的代码中有没有补充小玩意儿库存的东西?剩下0个。没有,没有任何补充。下面的答案帮我解决了这个问题。谢谢大家!是的,我意识到我没有变量保持0的问题,但我想不出一个方法来纠正它。谢谢,这很有效。是的,我知道变量保持0的问题,但我想不出一个方法来纠正它。谢谢,这很有效。是的,我知道变量保持0的问题,但我想不出一个方法纠正它的方法。谢谢,这是有效的。是的,我认识到变量保持0的问题,但我找不到纠正它的方法。谢谢,这是有效的。