+ 4
How do you nest loops in C++
I've tried this method over and over but it keeps giving me errors: https://code.sololearn.com/ccp91I1Mj5Pp/#cpp I don't think it's featured in the course either. Help!
4 Answers
+ 2
#include <iostream>
using namespace std;
int main() {
int apt = 0;
int ski = 0;
int comp = 0;
int count = 0;
while (count<=700) {
cin >> apt >> ski >> comp;
int sum = apt+ski+comp;
if (sum>=80) {
cout << "You have been nominated for selection of CEO." << endl;
}
else {
cout << "You have not been nominated for selection of CEO." << endl;
//count += 1; take this statement of the else block
}
count += 1;
}
return 0;
}
+ 2
OR
Instead of while loop, use for loop
//while (count<=700) {
for (count = 0; count<=700;count++){
cin >> apt >> ski >> comp;
int sum = apt+ski+comp;
if (sum>=80) {
cout << "You have been nominated for selection of CEO." << endl;
}
else {
cout << "You have not been nominated for selection of CEO." << endl;
}
}
0
a loop in another loop
means same as loop you make 2D matrix by c++ coding you can see loop in loop
0
Thank you so much!