CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// Created by Miriam Rosa⚘
#include <iostream>
using namespace std;
int main() {
string phrase1;
int cont=0;
cout << "Write a phrase: ";
cin >> phrase1;
cout << phrase1;
phrase1 = ' '+phrase1;
for(int i=0; i<phrase1.length(); i++)
{
if (phrase1[i]==' ' && phrase1[i+1]!=' ')
{
++cont;
}
}
cout<<"\nThe amount of words are : " << cont;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run