Close, but no banana. You need to store the letters in a char array, and the count should not be subtracted by 1 at the end. IE:
#include <iostream>
#include <stdio.h>
#define MAXLETTERS 100;
using namespace std;
int main(int argc, char* argv[])
{
char letters[MAXLETTERS+1];
char letter = 0;
int count = 0;
double ppl = 0;
char done;
double finalCost = ppl * (count - 1);
cout << "\tWelcome to My Price Per Letter Calculator!\n";
cout << " What is your next character? Type '*' to end : ";
do
{
cout << " What is your next character? Type '*' to end : " << flush;
letter = fgetc(stdin);
if (letter != '*')
{
letters[count] = letter;
count++;
}
}
while (letter != '*' && count < MAXLETTERS);
letter[count] = 0; // Terminate the string.
cout << " What is the price per letter to pay? ";
cin >> ppl;
cout << " You have "<< dec << count << " letters at $"<< ppl
<< " per letter, and your total cost is $" << finalCost << "."
<< endl;
cout << "Press any key to finish: " << flush;
fgetc(stdin);
return 0;
}
Note the combination of C and C++ i/o functions. This is a case where C functions are sometimes simpler to use than C++, yet can be used interleaved as shown. Exercise for you - convert the fgetc() function calls to C++ ones that will return after getting one character... :-) In …