+ 1

Help!

I may be a chaotic coder but I can't see why my codes are not working: #include <iostream> using namespace std; int main() { int prime=1; int divider=1; int counter; for (prime =1;prime < 10;prime++){ for (counter=1;counter == prime ;counter++){ counter = prime % divider ; } cout<< "prime " << prime << " % " << divider << " = " << counter << endl; } return 0; } Can someone clarify?

26th Jan 2018, 1:01 PM
HOGELING TEKENtechniek
HOGELING TEKENtechniek - avatar
3 ответов
+ 2
What should it do? the condition counter==prime in the second loop is never true when prime is more than 1 (because you set counter to 1), so the inner loop is not executed at all
26th Jan 2018, 2:48 PM
michal
+ 2
Btw: this program should show all the modulus' between 1/1 and 10/10.
26th Jan 2018, 5:25 PM
HOGELING TEKENtechniek
HOGELING TEKENtechniek - avatar
+ 1
Ah, my bad. counter should be divider!
26th Jan 2018, 2:49 PM
HOGELING TEKENtechniek
HOGELING TEKENtechniek - avatar