oct 26 in class problem
#include <cstring>
#include <iostream>
using namespace std;
int strlen (char* strx, int size){
int count;
int word;
bool space;
for (int x=0; x<size;x++)
{
count++;
if(isspace(strx[x])){
count--;
if (space==false){
word++;}
space=true;
}
}
cout<<"total letters excluding spaces is "<<count<<"/n";
cout<<"number of words "<<word<<"/n";
cout<<"average number of letters per word "<<count/word<<"/n";
}
int main() {
//define the array
const int length=50;
char name[length];
//prompt for the string
cout<< "enter a string please";
cin.getline(name, length);
//pass its length and the array as params to function
strlen (name,strlen(name));
cin.ignore();
}
#include <iostream>
using namespace std;
int strlen (char* strx, int size){
int count;
int word;
bool space;
for (int x=0; x<size;x++)
{
count++;
if(isspace(strx[x])){
count--;
if (space==false){
word++;}
space=true;
}
}
cout<<"total letters excluding spaces is "<<count<<"/n";
cout<<"number of words "<<word<<"/n";
cout<<"average number of letters per word "<<count/word<<"/n";
}
int main() {
//define the array
const int length=50;
char name[length];
//prompt for the string
cout<< "enter a string please";
cin.getline(name, length);
//pass its length and the array as params to function
strlen (name,strlen(name));
cin.ignore();
}