Contest Problem

This is a discussion on Contest Problem within the C++ Programming forums, part of the General Programming Boards category; Hey everyone. I'm very new to c++, and I'm busy trying to teach myself it. My school feels the need ...

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    5

    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.

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,702
    Use code tags, then you'll get plenty of help...

    gg

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    32
    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.
    - Tigs

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Laptop Problem
    By Boomba in forum Tech Board
    Replies: 1
    Last Post: 03-07-2006, 06:24 PM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 02:04 AM
  4. Eighth Contest -- Vote Now!!!
    By ygfperson in forum Contests Board
    Replies: 10
    Last Post: 11-13-2002, 03:33 PM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 09:37 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21