searchingWrite函數conseclets它將接收一個字符串作爲參數。該函數將確定字符串中兩個或多個連續字母相同的所有情況。如何編寫一個函數來計算字符串中的連續字母相同
例如,如果「Barrymoore」發送到該函數,則會說該字符串中有連續的字母r和o。但是如果「布什」被髮送到函數,它會說沒有兩個連續的字母是相同的。
這裏是我的代碼與它的問題是,當我把在信中找到它找到它但不連續
#include <iostream>
#include <string>
using namespace std;
int main()
{
char searching='\0';
string name=" ";
int counter =0;
cout<<"Enter a name : "<<endl;
getline(cin, name);
cout<<"Which letter would you like to count the number of times it appears: "<<endl;
cin>>name;
for(int i=0; i<name.length();i++){
if(sentence[i]==searching){
counter++;
}
}
cout<<"The letter " << searching << " appears "<< counter << " times ";
return 0;
}
當創建一個[最小,完整,可驗證例子](http://stackoverflow.com/help/mcve),如果它實際*編譯*(除非你詢問構建錯誤),它通常是一個加號。不要只是將代碼重新輸入到問題中。請將其複製並粘貼。 –
至於你的問題,試着先在紙上解決它。在紙上寫下輸入字符串,並試圖找出如何計算連續字符。 –
你需要算法還是已經有算法?如果你需要一個,請特別要求。如果你有一個,請解釋它並向我們展示你實現它的嘗試。 –