- Back to Home »
- c++ , calculate , code , coding , program , project , project c++(basic) , sentence , words »
- Program in C++ to calculate words in sentence
Posted by : Unknown
Wednesday 24 December 2014
This program demonstrate the calculation of words in sentence in a console application using C++
#include<iostream>
#include<conio.h>
using namespace std;
void main() {
char arr[1000] = { '-' };
int result = 0;
cout << "Enter the sentence use + for spaces and - to end sentence" << endl << endl;
for (int i = 0; i < 1000; i++){
cin >> arr[i];
if (arr[i] == '-'){
i = 2000;
}
}
for (int i = 0; i < 1000; i++){
cout << arr[i];
if (arr[i] == '-'){
i = 2000;
}
}
for (int i = 0; i < 1000; i++){
if (arr[i] == '+') {
result++;
}
}
cout << endl<< "Number of Words are: " << result+1;
_getch();
}
#include<iostream>
#include<conio.h>
using namespace std;
void main() {
char arr[1000] = { '-' };
int result = 0;
cout << "Enter the sentence use + for spaces and - to end sentence" << endl << endl;
for (int i = 0; i < 1000; i++){
cin >> arr[i];
if (arr[i] == '-'){
i = 2000;
}
}
for (int i = 0; i < 1000; i++){
cout << arr[i];
if (arr[i] == '-'){
i = 2000;
}
}
for (int i = 0; i < 1000; i++){
if (arr[i] == '+') {
result++;
}
}
cout << endl<< "Number of Words are: " << result+1;
_getch();
}