# Contest Problem

• 03-09-2003
Drealoth
Contest Problem
Hey everyone.

I'm very new to c++, and I'm busy trying to teach myself it. My school feels the need to teach Turing (even when we have Visual Studio 6.0 installed on all of the computers), which is probably the most useless programming language in existance. Moving from it to c++ is probably harder than if I had had no programming experience beforehand.

Anyway, I'm a member on the USACO contest site, and I've been working for a good week trying to figure out the syntax to do this problem.

You're given two strings of length 1 to 6, consisting of uppercase letters. You're then supposed to find the product of the string, using the A = 1, B = 2, ... , Z = 26.

Whenever I do it, I get a huge negative number.

Here's my code:

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

int main()
{
char strGroupName [6];
char strCometName[6];

ifstream fin ("ride.in");

fin.getline (strCometName,10);
fin.getline (strGroupName,10);

int intGroupTotal, intCometTotal = 1;

for (int x = 0; x != 6;x++)
{
if (strGroupName[x] >= 'A' && strGroupName [x] <= 'Z')
{
for (int i = 65;(char) i <= 'Z';i++)
{
if (strGroupName[x] == (char) i)
{
intGroupTotal = intGroupTotal * (i - 64);
}
}
}
}

cout << intGroupTotal;

return 0;
}

Any help is greatly appretiated.
• 03-09-2003
Codeplug
Use code tags, then you'll get plenty of help...

gg
• 03-09-2003
tigs
Isn't a char -128 to 127? So something with an ASCII value of 28 would come out -100. Unsigned char (or byte) is 0-256 I think.