+ 1
What's wrong with this code
This is a code coach activity #include<iostream> #include<cstring> #include<math.h> using namespace std ; int main(){ cout<<"hello world"<<endl<<endl; char s[100]; int count=1; cin.getline(s,100); for(int i=0;i<strlen(s);i++) { if(s[i+1]==' ') { count++; } } cout<<"total number of words are "<<count<<endl; int avgLetter=strlen(s)/count; cout<<" the average letter is: "<<ceil(avgLetter)<<endl; return 0; }
3 Respostas
+ 1
Solaz
Maybe you should change the data type of avgLetter from int to float? ceil does nothing to int.
also, remove the hello world cout, as well as the other couts.
just cout the ceil(avgLetter).
0
Save this code in Code Playground as public, then edit your question and include a link to your saved code in the question description. This way, we can test it.
Also, pls include in your question an explanation of your difficulties. This way, we know what you need an answer to.
0
Solaz why didn't you just use string? it is more versatile.
also, there is a condition in the problem that states remove all punctuation. You did not provide for that. Possibly problematic on other tests...