Help please
thank everyone for there help....
is it a bad sign I couldnt figure this out? lol
Not if your just learning.
@ dput, that code will take into account the .
@softrix Yeah it is only the 4th week of programming 1. I did great on the other projects and got worried when I could not figure this one out
A sentence cannot be completed without a proper '.' correct?
(Excluding questions and exclamations =D - can add if necessary)
Hopefully OP discovers his/her solution.
A full stop is not a letter so shouldn't be calculated. :) - plus of the user forgets the . it goes in a indefinite loop ;-)
try this:
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 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
string sentence;
double price, total = 0;
int index = 0;
cout << "Enter PPL: $";
cin >> price;
cout << "Enter sentence: ";
cin >> sentence;
for (;;)
{
if (sentence[index] == 0)
break;
else
{
if (sentence[index] >= 'a' && sentence[index] <= 'z' ||
sentence[index] >= 'A' && sentence[index] <= 'Z')
total += price;
index++;
}
}
cout.precision(4);
cout << "Total was: " << total;
return 0;
}
|
Since a string is terminated by a 0, for loop will jump out when it finds the end of the string.
Yeah it is only the 4th week of programming |
Still early days, you'll get there :)
Topic archived. No new replies allowed.