PropellerAds
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();
}

Leave a Reply

Subscribe to Posts | Subscribe to Comments

PropellerAds
PropellerAds

Popular Post

Powered by Blogger.

- Copyright © BSCS -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -