Category : while-loop

I am writing code to solve a USACO problem (link if you are curious: http://www.usaco.org/index.php?page=viewproblem2&cpid=1013) and I tried running it but my program gets stuck in the while loop. I suspected an infinite while loop so tried cout << "stuck" at every while loop but surprisingly, the console only printed it once and runs forever. ..

Read more

#include <iostream> using namespace std; bool play_game(int n) { int guess; bool noguesses = false; int numofguesses = 0; cout << "Welcome to my number guessing gamen"; while (n!=guess && !noguesses) { if (numofguesses < 6) { cout << "n"; cout << "Enter your guess: "; cin >> guess; cout << "n"; cout << "You ..

Read more

I have a c++ doubly-linked list that I’m trying to implement for my Data Structures class and I keep getting stuck in this while loop. NOTE: I’m testing it with instructor-provided test data and the getting stuck happens only some of the time. Thanks in advance for any help anyone might be able to provide ..

Read more

I have a c++ doubly-linked list that I’m trying to implement for my Data Structures class and I keep getting stuck in this while loop in my deleteNode() method. The loop is meant to advance the ‘current’ node to the one I want to delete. NOTE: I’m testing it with instructor-provided test data and the ..

Read more

#include<iostream> #include<math.h> using namespace std; int main() { int num,count,temp,sum=0,powr,rem; cin>>num; temp=num; while(temp>0){ ++count; temp=temp/10; } while(num>0){ rem=num%10; powr=round(pow(rem,count)); sum+=powr; num=num/10; } if(sum==num){cout<<"true";} else cout<<"false"; return 0; } This code only prints false for some reason but never true, and I’ve tried running through it with a debugger and it correctly calculates the value of ..

Read more

I need help with changing my password. This is the part when the interface of the project opens and reopens. int main() { Padlock Lock; int D = 0; int m = 1; Lock.type_keycode(); do { Lock.type_keycode1(); Lock.set_password(Lock.get_keycode()); Lock.set_userinput(Lock.get_keycode1()); Lock.Lockopen(Lock.get_password(), Lock.get_userinput()); cout << "TEST " << endl; if (Lock.get_password() == Lock.get_userinput()) { Lock.Lockoption(Lock.get_password(), Lock.get_userinput()); } ..

Read more