help

I needed the help to complete my c++ project. i could not.
I have to grab the percentage from the user input string
it must be in one or more digit followed by decimal followed by one or more digit and followed by % sign
This is what im up to.





#include <iostream>
#include <cctype> // for character testing functions
#include <string> // to use string objects (variables)
using namespace std;
bool readPercentage(string &percentageStr);
//double percentStrToNum(string percentageStr);
int main ()
{
string percentageStr = "hello";
cout <<"Ingredient :" <<endl;
cout << boolalpha << readPercentage(percentageStr) << endl;

while (cin.get() != '\n')
; // null statement
cout << "percentage " <<percentageStr <<endl;

return 0;
}

bool readPercentage(string &percentageStr)
{
char ch;
int count;
percentageStr = "";
count =0;

do
{
cin.get(ch);
if (isdigit(ch))
{
percentageStr += ch;
count++;
}
else
break;
}
while (true);

if (ch = '.')
{
percentageStr += ch;

}


count = 0;
do
{
cin.get(ch);
if (isdigit(ch))
{
percentageStr += ch;
count++;
}
else
break;
}
while (true);




if (ch = '%')
{
percentageStr += ch;

}


cin.putback(ch);
return true;



}
//double percentStrToNum(string percentageStr);

The output should look like this prototype given







Run1:
Ingredient:
high-fructose corn syrup (2.1%)
Enter percent limit: 5.7
Percentage of 2.1 within limit
Run2:
Ingredient:
sodium nitrate: 0.1%
Enter percent limit: 0
Percentage of 0.1 above limit
Run3:
Ingredient:
monosodium glutamate (20.0g)
No percentage listed with ingredient.
Topic archived. No new replies allowed.