![]() |
|
#1
|
|||
|
|||
Need help with enums and function programhello. i am writing a program where it will read data from a file. and each token read will be determine to be a enum type of either IDENTIFIER, ARITHMETIC, ASSIGNMENT, or ILLEGAL. the program will then print out each token and the corresponding enum type for it. each type has logical rules and boundaries. the data being read is:
area = pi * r * r; _perimeter = 2 *( l + w); volume += 2pi r times r square_ ; //Step 9.a switch (transactionCode) { case 'd' : interest = princ_ipal * 1.06; + transactionAmount; amountDeposited = amountDeposited + transactionAmount; __numberOfDeposits ++; break; 1default; } i have stored this project in a file called data.txt. and here is my program so far. it determines each token and the type of token correctly. however. after running, it only shows the token enum type and not the token. here is my code: CPP / C++ / C Code:
the problem is the output which looks something like Token Token type area identifier = assignment pi identifier * arithmetic r identifier and so on.... however it's outputting this: Token Token type identifier assignment identifier arithmetic identifier where the type of token is being displayed but no token itself. does anyone know what the error is? thank you for all your time by the way. this is intro c++. and i'm using visual studio |
|||
|
#3
|
|||
|
|||
|
hmm....well. i'm thinkin it's something to do with the "infile >> token" i have in my tokenType ReadAndDetermineTokens(ifstream & inFile) function. all i know right now is that it's definitely an error within my 2 functions. i mean, there's really nothing else. but i still don't understand where an error might be. do you see any errors going through it? i'm pretty sure it has something to do with reading the file or infile-ing the token. maybe i put the infile >> token in the wrong place?
thank you so much for helping :-) |
|
#4
|
||||
|
||||
|
i think i know what it is,
You need to ReadData, and DetermineToken seporatly. Basically you read data, and return a token(not the TokenType) than you use that to DetermineToken(to see whcih one it is, and retuern that)... i think does that make sense? __________________
Xrum! |
|
#5
|
|||
|
|||
|
hmm... well the way i have it set up. is that the getTokenAndTokenType() function reads the file in a loop. in my getTokenAndTokenType(), i read the file as a loop, and call the function ReadAndDetermineTokens() within the loop, so that each token read can go through the conditions, and then back into getTokenAndTokenType() to increment each token type count as well as print to screen. i mean it reads the tokens, goes through the conditions in ReadAndDetermineTokens() correctly, goes back into getTokenAndTokenType() and correctly increments the token type counters. but it's just not printing the token. i guess it's a little misleading for the function name getTokenAndTokenType() because i made a change and had it indeed read and determing tokens separately instead of in the same function. now it reads in getTokenAndTokenType(), and determines in ReadAndDetermineTokens().
so what it comes down to is....i don't really understand what you're telling me to do means. |
|
#6
|
|||
|
|||
|
by the way. it is required i use enums. that's why i have to do it like this. otherwise i'd do everything in main. and i'd be done pretty fast haha.
again. i really appreciate the help. thank you so much. i'm struggling with this one as well as my other project in my other thread. it's the same problem as harleyrider has. he's in my class. haha. everything is due tomorrow and i'm panicking. plus final is tomorrow too!!! |
|
#8
|
|||
|
|||
|
Quote:
CPP / C++ / C Code:
CPP / C++ / C Code:
One way to fix this might be to pass the string "token" to your function, CPP / C++ / C Code:
CPP / C++ / C Code:
CPP / C++ / C Code:
|
|
#9
|
|||
|
|||
|
THANK YOU GUYS SOO MUCH!!! YES!! thanks especially to sokar. suggestion worked perfectly!! of course thank you too kacyndra!! thanks guy for the time and help. nicee, i got one down , another to go now....
:-( haha. any help with that one too perhaps haha it's under need help with simple 1D array thread. lol, that's if you have nothing else to do of course, no obligation to help of course. again, thanks so much |
Recent GIDBlog
Install Adobe Flash - Without Administrator Rights by LocalTech
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Can enum have same name as class? | crystalattice | C++ Forum | 3 | 08-Dec-2004 16:43 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The