Hey everyone. I am new to C++ and I am working on some homework from a class of mine. The program is supposed to prompt the user to enter a sentence followed by a '.' or '!'. The program will then count the relevant letter (e,d,c,h,k,and j) in the sentence and display the count of each letter. Along with this, each relevant letter is given a value and the program will sum up the total value and display it at the end. This is what I have come up with so far. It compiles fine but gets stuck in an input loop. Any suggestions?
So. You want the user to enter an entire sentence. If so, non of your code makes any sense.
If you want a sentence. Then it has to be string text;
And you will have to use getline(cin,text); instead of cin >>.
Now. if text is say "Hey there". The reason non of your code will make any sense is that, non of your if statements nor the while loop does anything related to that sentence. Do you understand what I mean?
So is there anyway using only <iostream> that I can read each character of the sentence individually? For example, using "Hey there!" the user should enter this and then the prgram should check each character of the string and run accordingly in the while loops. Displaying the count of each letter and the total score tallied up.
As far as I know, There is only 1 way,but its dumb as hell. Basically just ask the user how many characters his sentence is gonna be. Then create an array, then tell the user to type in each character of that sentence one at a time. Basically what Im trying to say is, No.
We are expected to complete this assignment with only the directories we have learned thus far, and using a while loop and not for loops. Being new to C++ don't know any other way to do any of this unless I use outside source. Which I can do, but it would totally bogus to expect us as students to implement things we have yet to learn in lecture. I am out of ideas.
Okay I figured it out using a do-while loop. Like fin2code said I just needed to prompt for the phrase in the loop and use && relation instead of ||. Thanks everyone for the help. Here is the final code if anyone is curious: