Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

#include<cstring> int Word_count(char *); //Main function void main() {//Start m

ID: 3618624 • Letter: #

Question

#include<cstring>

int Word_count(char *);

//Main function

void main()

{//Start main

     const int size=50;

     char String1[size];//Holds string

     int words;

     //Inputting String

     cout<<"Enter String ";

     cin.getline(String1,size);

     //Function call   

     words=Word_count(String1);

      //Outputting Number of returnedword count

     cout<<"Number ofwords:"<<words<<endl;

     //Statement to Pause System

     system("pause");

}//End of main

//Function Definition

int Word_count(char *str)

{

     //Variable declaration

     int count=1;//Holds wordcount

     //Loop to count words

     while(*str!='')

     {

          if(*str==' ')

              count++;

              str++;

     }

    

     //Returning count value tomain

     return count;

}

//End of function

//Header file section

#include<iostream>

#include<cctype>

#include<cstring>

using namespace std;

//Function prototype

int Word_count(char *);

//Main function

void main()

{//Start main

     const int size=30;

     char String1[size];//Holds string

     int Average_words;

     //Inputting String

     cout<<"Enter String up to(20)characters";

     cin.getline(String1,size);

     //Function call   

     Average_words=Word_count(String1);

      //Outputting Number of returnedword count

     cout<<"Number of Letters in Eachword:"

                                    <<Average_words<<endl;

     //Statement to Pause System

     system("pause");

}//End of main

//Function Definition

int Word_count(char *str)

{

     //Variable declaration

     int count=1,average=0;//Holdsword count

     //Loop to count words

     while(*str!='')

     {

          if(*str==' ')

              count++;

              str++;

     }

     average=20/count;

     //Returning count value tomain

     return average;

}

Explanation / Answer

if all that code is part of one .cpp file then it would run because you've got more than one #include saying the same thing and calling using more than once. so i suggest separating the different sections of code first then take a second look because I notices some problems in the first one. like int Word_count(char *) should be int Word_count(char *str) because that's the way it is when you define it.