My task is: to write a program which reads characters one by one from the keyboard until the character ’q’ is entered. Use a loop with and bool variable for exiting the loop. At the end a string containing all entered letter should be printed on the screen (except the ’q’).
This is what i have so far and i am kind of stuck now, everytime i run it I am only able enter 1 character then the program stops---> this occurred after i wrote the last line with if(b==true)....... .
int main() { bool b; char input[80]; int i; b = false; while(b != true){ cout<<"Enter characters: "<<endl; cin>>input[i]; if(input[i] == 'q'){ b == true; break; } } if(b == true){ for(int j = 0; j < 1; j++){ for(int x = 0; x < 1; x++){ cout<<input[i]<<endl; } } } Please help. Thank you very much.
iand you aren't event incrementing it.b == true;does nothing you need = not ==. What is the b == statement after the loop? b will always be true, once you actually assign to it. Why are you using break? The while statement will already stop when you set b to true. What is the j for loop? It only does ever does the loop once, and the same for the x loop, which should be looping i times. Why not just assign '\0' to input[i] after the while loop and do cout << input?while (b != true). Instead you can just writewhile (!b).