Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,234 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,654 people online right now. Registration is fast and FREE... Join Now!




error C2061

 
Reply to this topicStart new topic

error C2061, error C2061: syntax error : identifier 'message'

Tuur
16 Mar, 2007 - 11:24 AM
Post #1

New D.I.C Head
*

Joined: 16 Mar, 2007
Posts: 4


My Contributions
Hi
I am kinda new here and i have got a problem wich I didn't manage to solve myself blink.gif

error C2061: syntax error : identifier 'message'

(I am trying to built a program which can make a number of a letter like: a=1 b=2 etc)
So could anyone take a look at it please?
because I can't get rid of it :S
here is the code:

CODE


#include <iostream>
using namespace std;
// functions declared:
void charint();

//:Global variables
char message[80] = {0};
int codeint[80] = {0};


void main() //------------------------main------------------
{
cout << "write your message (without spaces): \n";
cin >>message;
cout << message <<endl;
charint();

cout << codeint << endl;

}//-----------------------------------main-------------------



//Functions

void charint(void)
{

for ( int i=0; i <81; i++)
{
    if message[i] = 'a' // the error points to this line :S
    codeint[i] = 1    
    else
    if message[i] = 'b'
        codeint[i] = 2
    else
    if message[i] = 'c'
    else
    if message[i] = 'd'
        codeint[i] = 4
    else
    if message[i] = 'e'
        codeint[i] = 5
    else
    if message[i] = 'f'
        codeint[i] = 6
    else
    if message[i] = 'g'
        codeint[i] = 7
    else
    if message[i] = 'h'
        codeint[i] = 8
    else
    if message[i] = 'i'
        codeint[i] = 9
    else
    if message[i] = 'j'
        codeint[i] = 10
    else
    if message[i] = 'k'
        codeint[i] = 11
    else
    if message[i] = 'l'
        codeint[i] = 12
    else
    if message[i] = 'm'
        codeint[i] = 13
    else
    if message[i] = 'n'
        codeint[i] = 14
    else
    if message[i] = 'o'
        codeint[i] = 15
    else
    if message[i] = 'p'
        codeint[i] = 16
    else
    if message[i] = 'q'
        codeint[i] = 17
    else
    if message[i] = 'r'
        codeint[i] = 18
    else
    if message[i] = 's'
        codeint[i] = 19
    else
    if message[i] = 't'
        codeint[i] = 20
    else
    if message[i] = 'u'
        codeint[i] = 21
    else
    if message[i] = 'v'
        codeint[i] = 22
    else
    if message[i] = 'w'
        codeint[i] = 23
    else
    if message[i] = 'x'
        codeint[i] = 24
    else
    if message[i] = 'y'
        codeint[i] = 25
    else
    if message[i] = 'z'
        codeint[i] = 26
    else
    codeint[i] = 0
}
}


I hope anyone can find the problem.

(srr for my english)
User is offlineProfile CardPM
+Quote Post

Mrafcho001
RE: Error C2061
16 Mar, 2007 - 12:03 PM
Post #2

D.I.C Addict
Group Icon

Joined: 1 Nov, 2005
Posts: 753



Thanked: 5 times
Dream Kudos: 120
My Contributions
CODE

if( condition )
{
     statement;
}
else if( condition )
{
     statement;
}
else
{
     statement;
}


EDIT:

you can do something like this:

CODE

for( int i = 0; i < sizeOfCharArray; i++)
{
intArray[i] = static_cast<int>(charArray[i]) - 96;
}


character 'a' is 97 when its casted to an integer, knowing that you can assume that the rest increment by one, so if you type cast a char to an int and subtract 96 from it, it should give you the same number output in the int array...

This post has been edited by Mrafcho001: 16 Mar, 2007 - 12:10 PM
User is offlineProfile CardPM
+Quote Post

Tuur
RE: Error C2061
17 Mar, 2007 - 12:02 AM
Post #3

New D.I.C Head
*

Joined: 16 Mar, 2007
Posts: 4


My Contributions
Thanks a lot smile.gif
it works great!
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 03:59PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month