Posted by : Waqas Javed 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

Contact Us

Stay updated for more codes if we u want any code write us by commenting below or email us.
If you want to hire us for your semester project email us at above given email or call or message
Email: 14bscswjaved@seecs.edu.pk
Phone no: 0308-8109708

Popular Post

Powered by Blogger.

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