Computing.Net > Forums > Programming > c++ lil annoying problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

c++ lil annoying problem

Reply to Message Icon

Name: kimib
Date: December 3, 2004 at 14:51:37 Pacific
OS: duno
CPU/Ram: duno
Comment:

Please do not laugh at my lil knowledge of c++ :-)

code:

#include<iostream>
#include<string.h>
#include<fstream>

using namespace std;

int main ()
{
int sum = 0;
string input;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
cout << "Enter a word" << endl;
cin >> input;


//word value

for ( int i=0, i< input.length() , i++)
{
q = alphabet.find(input[i])
sum+= 1 + q

}
cout << input.length()<<endl;
cout << " sum " << sum << endl;

system ("pause");
return 0 ;
}
trying to do the simplest of tasks(Well firstly)...

all i want is to input a word, and assign a=1 b=2 etc and find the sum of the word. For some weird reason i'm getting a syntax error before ' ; ' .....
system ("pause");
and it won't let my for loop work!!
syntax error before ' ) '.....
, i++)

I know you guys are great :-)



Sponsored Link
Ads by Google

Response Number 1
Name: Sord
Date: December 3, 2004 at 16:08:29 Pacific
Reply:

Probably because you used commas in your for loop where semicolons should be.

Use:
for (int i = 0; i < input.length(); i++)


0

Response Number 2
Name: Sord
Date: December 3, 2004 at 17:27:56 Pacific
Reply:

Oh, you also need a semicolon at the end of each line in the for loop, a variable called q, and cin can't use string's like that (I think)


0

Response Number 3
Name: Sord
Date: December 3, 2004 at 17:34:51 Pacific
Reply:

Here is a corrected and little optimized version:
http://home.earthlink.net/~valiantsoul/test.cpp

(Note I will not keep it on my server for very long so don't rely on me doing so)


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


How can I MD4 in vb.net How powerful is C?



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: c++ lil annoying problem

c var precision problem (equations) www.computing.net/answers/programming/c-var-precision-problem-equations/12303.html

C++ class redefinition problems www.computing.net/answers/programming/c-class-redefinition-problems/1587.html

C++ I/O problem www.computing.net/answers/programming/c-io-problem/8735.html