so my program prompts the user for a command which is put into and array using c
ID: 3527801 • Letter: S
Question
so my program prompts the user for a command which is put into and array using cin>>commandarray; the command is a key word a space then a number. then the first part of the array is copied to another array which compares it to some commands and runs a function accordingly. ex. user command: power 3 correct output:powering 3 all commands only take 6 spaces so my output should be: cout<<"powering"<<commandarray[6]<<commandarray[7].........; right? all it puts out is "powering" thoughExplanation / Answer
You probably shouldn't use cin in this case, as it would end your cin at the whitespace. If you were to input power 3, your array would only end up power and the 3 would be left in the cin buffer. Try changing the cin into cin.getline(commandarray,7); This should also grab the whitespace and the number which you seem to want.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.