Word Counter

I am currently working on an assignment and I can't really figure out what is not working.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
using namespace 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.

Please help me figure out what I am doing wrong.
Calculate finalCost *after* you know what the values of count and ppl are.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
using namespace 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";
}
Amazing :) thanks!!! Idk why it never occurred to me to do those separately like that.
Topic archived. No new replies allowed.