I'm new to C++ programming and this is the task that i've to do, but i can't get the desired output even after trying and trying. Can anyone please look into code and let me know what should do, i know my code is incomplete but i don't know how to proceed from here.
Task: Write a program, using functions only, with the following features.
- Program reads paragraph(s) from console and stores in a string.
- Program then counts the occurrences of double letter appearing in any word of the paragraph(s) and outputs the characters along with its number of occurrences.
- If a double letter is appearing more than one time the program should show this only one time along with its total frequency in paragraph.
- Output letters must be in sequence. Sample input (file): Double bubble deep in the sea of tooth with teeth and meet with riddle. Sample output: bb 1 dd 1 ee 3 oo 1
This is my code:
#include <iostream>
#include <conio.h>
#include <cstring>
#include <ctime>
using namespace std;
int counter = 0;
char alphabets[26] = { 0 };
void alternatives();
int main() {
alternatives();
_getch();
return 0;
}
void alternatives() {
char str[] = "Double bubble deep in the sea of tooth with teeth and meet with riddle.";
int count = 0;
for (int j = 0; j < strlen(str); j++)
str[j] = tolower(str[j]);
for (int i = 0; i < strlen(str); i++) {
if (str[i] == str[i + 1]) {
counter++;
cout << str[i] << str[i + 1] << "\t" << counter << endl;
}
counter = 0;
}
}
Output:
bb 1 ee 1 oo 1 ee 1 ee 1 dd 1