Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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 :-)

Probably because you used commas in your for loop where semicolons should be.
Use:
for (int i = 0; i < input.length(); i++)

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)

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)

![]() |
How can I MD4 in vb.net
|
How powerful is C?
|

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