The cost of a message depends in the number of words in the message.Given that the cost of each word is shs 20. Design a program that ask the user to enter the message and then it outputs:-
1. The number of words in the message.
2. The total cost of the message.
1
Expert's answer
2012-11-16T05:15:04-0500
#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"; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment