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

The following is the problem, along with the code that I do have. Ipretty much h

ID: 3618806 • Letter: T

Question

The following is the problem, along with the code that I do have. Ipretty much have it solved, but with a minor, somewhat stupidquestion. Any help is appreciated.

Write a program that prompts the user to input a string. The outputwill be the total number of characters in the string,
the total number of consonants in the string, and the total numberof vowels in the string.
Be sure to prompt for input and to label your output. The codeneeds to handle the string as a character array (C-string) and as astring data type.

Basically, this is what I have. But He wants it to outputtwice. For example:
Enter a string: Program

This has 7 characters, 2 vowels and 5 consonants (C-String).

This has 7 characters, 2 vowels and 5 consonants (String Datatype).


My output is a little different, but what I am brainfarting on, isthis. Do I just need to repeat the output twice, with C-String andString Data type after it, or
is it asking for something completely different? Dumb question Iknow, but I tend to over think things sometimes. Thanks.

#include<iostream>
#include<conio.h>

using namespace std;

int main()
{
    //initialize variables
    char input[100];
    int length=0, ch=0, vowel=0, consonant=0;
  
    //this will let the user input the string
    cout<<"Enter a string: ";
    cin.getline(input, 100);
  
    //performs a loop to compare each character inthe string
    for(int i=0; i<strlen(input); i++)
    {
           if (input[i]!=' ')
              ch++;
           //count vowels
           if(input[i]=='A'||input[i]=='a'||input[i]=='E'||input[i]=='e'||input[i]=='I'||input[i]=='i'||
           input[i]=='O'||input[i]=='o'||input[i]=='U'||input[i]=='u')
              vowel++;
           //count consonants
           else if(input[i]=='B'||input[i]=='b'||input[i]=='C'||input[i]=='c'||input[i]=='D'||input[i]=='d'||
           input[i]=='F'||input[i]=='f'||input[i]=='G'||input[i]=='g'||input[i]=='H'||input[i]=='h'||
           input[i]=='J'||input[i]=='j'||input[i]=='K'||input[i]=='k'||input[i]=='L'||input[i]=='l'||
           input[i]=='M'||input[i]=='m'||input[i]=='N'||input[i]=='n'||input[i]=='P'||input[i]=='p'||
           input[i]=='Q'||input[i]=='q'||input[i]=='R'||input[i]=='r'||input[i]=='S'||input[i]=='s'||
           input[i]=='T'||input[i]=='t'||input[i]=='V'||input[i]=='v'||input[i]=='W'||input[i]=='w'||
           input[i]=='X'||input[i]=='x'||input[i]=='Y'||input[i]=='y'||input[i]=='Z'||input[i]=='z')
               consonant++;
    }
  
    //This will display the output
    cout<<"Total number of Characters:"<<ch<<" ";
    cout<<"Total number of Consonants:"<<consonant<<" ";
    cout<<"Total number of Vowels:"<<vowel<<" ";
  
    _getch();
    return 0;
}

Explanation / Answer

please rate - thanks he's asking you to process the data twice. once as aC_string(character array), once as a string. you've done thec_string now add the code to do it as strings so for example declare string inputs; after the code you've done add the following inputs=input; instead of strlen, use inputs.length() etc any questions message me