I need to write code that checks whether or not the user inputted the same word twice, and if so, it will output a message stating that they did. So far, I have:
#include <iostream>
using namespace std;
int main(){
string previous = "";
string current = "";
while (cin>>current); {
if(current == previous); {
cout<<"repeated word";
}
previous=current;
}
}
It compiles, but it won’t output the message whenever the user types in the same word twice.
if you notice, your code contains
;in places it should not contain.for example, if you place it after a
while (cin >> current)then code you wanted to run, won’t.try this: