Answer to Question #17077 in C++ for kassali anisah

Question #17077
if the cost of the MSG depend on the number of words ,given that each word costs 20shs,desind a program that outputs the number of words in the msg and total costs
1
Expert's answer
2012-10-24T10:46:07-0400
#include<iostream>
using namespace std;

char msg[200];
int n=0, i=0;

void main(){
cout<<"enter a message: ";
gets(msg);
while ((msg[i]==' ')&&(msg[i])) i++;
if ((msg[i]!=' ')&&(msg[i])) n++;
while (msg[i]){
& if ((msg[i]==' ')&&(msg[i+1]!=' ')&&(msg[i+2]!=NULL)) n++;
& i++;
}
cout<<msg<<"\n";
cout<<"the number of words is "<<n<<"\nthe price is "<<0.2*n<<"shs.\n";
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS