can anyone help me? with my hwk h06 dont know what im doing wrong? the pdf instruction are down below starting at pg 15
http://faculty.orangecoastcollege.edu/sgilbert/books/f17/Ch04-MoreStringsAndLoops.pdf
or
https://drive.google.com/file/d/0BzDKOi5LNlDhb2JVaUZZVDFwV0E/view?usp=sharing
————————————————————————-
int run()
{
/*
Describe the inputs: enter a string
outputs: the sum of the string.
and calculations here.
*/
// 1. Title and heading
cout << STUDENT << “-” << ASSIGNMENT << “-Number Sumer” << endl;
cout << “—————————————–” << endl;
// 2. Input section
cout << “Enter a string: “;
string str;
getline(cin, str);
// 3. Processing section
int sum = 0;
int num = 0;
// Your code goes here
//before the loop
for (size_t i = 0, len = str.size(); i < len; i++)
{
//inside the loop
if(str.at(i) >= ‘0’ && str.at(i) <= ‘9’)
{
int counter = str[i] – ‘0’;
num = num * 10 + counter – num;
sum += num;
}
else
{
num = 0;
}
}
// 4. Output section
cout << “The sum is [” << sum << “]” << endl;
return 0;
}
TESTING H06–soctavio + Input of aa11b33->44 X Input of we69a9es61449: expected [533] but found [497] +Input of a7Ørg65h8duwchdnb15->158 Input of yl39x->39 + Input of 7 11-18 +Input of d36->36 X Input of ut80k770: expected [850] but found [787] X Input of a1234bb11: expected [1245] but found [1047] +Input of 5hocolale->7 + Input of t5k2z2nov016-15 X Input of ws569o85oqwrp75om1: expected [730] but found [685] +Input of 9y4h4->17 +Input of 4p->4 X Input of 71f1mlz4247wb: expected [4319] but found [3581] +Input of a->0 H06: soctavio : ALL TESTS-PASS 10/ 15 (67%). MTUWNTM4NDE2Nzpzb2N0YXZpbzpIMDY6Nj YuNj cl ~/workspace/cs150/hw/h06/
Expert Answer
Answer:Found Error in the following
if(str.at(i) >= ‘0’ && str.at(i) <= ‘9’)
{
int counter = str[i] – ‘0’;
num = num * 10 + counter – num;
sum += num;
}
eg:a1234bb11
for i==1
num=0
sum=0
for i=1
counter = 1
num = 1
sum +=1;
for i=2
counter=2
num=1*10+2-1=11(according to your formula)
sum=11