#include <iostream>
usingnamespace std;
int main(int argc, char *argv[]) {
char letter;
int count = 0;
double ppl = 0;
double finalCost = ppl * (count - 1);
cout << "\tWelcome to the word counter!\n";
cout << " What is your next character? Type '*' to end : ";
cin >> letter;
for ( ; letter =! '*'; count++); {
cout << " What is your next character? Type '*' to end : ";
cin >> letter;
}
cout << " What is the price per letter? ";
cin >> ppl;
cout << " You have " << (count - 1) << " per letter, and your total cost is $" << finalCost << ".";
system("pause");
return 0;
}
I am trying to create a word counter program that asks for the price per letter and then asks for the sentence they are writing. The app should then calculate the number of letters and give the total cost similar to:
You have 40 letters at $3.45 per letter, and your total is $138.00.
Everything compiles fine but when I run it the inputs don't work and it outputs:
You have -1 per letter, and your total cost is $-0.
#include <iostream>
usingnamespace std;
int main() {
char letter;
int count = 0;
cout << "\tWelcome to the word counter!\n";
while( cout << " What is your next character? Type '*' to end : " &&
cin >> letter && letter != '*' ) ++count ;
double ppl ;
cout << " What is the price per letter? ";
cin >> ppl;
double finalCost = ppl * /*(count - 1)*/ count ; // **** here
cout << " You have " << count << " letters @ " << ppl
<< " per letter, and your total cost is $" << finalCost << ".\n";
}