Archived

This topic is now archived and is closed to further replies.

ThomasSauder

Help! :)

Recommended Posts

Error : C:\Documents and Settings\TJ\Desktop\Test Program\TestProgram.cpp(30) : error C2065: ''If'' : undeclared identifier C:\Documents and Settings\TJ\Desktop\Test Program\TestProgram.cpp(31) : error C2143: syntax error : missing '';'' before ''{'' C:\Documents and Settings\TJ\Desktop\Test Program\TestProgram.cpp(36) : error C2065: ''Else'' : undeclared identifier C:\Documents and Settings\TJ\Desktop\Test Program\TestProgram.cpp(36) : error C2146: syntax error : missing '';'' before identifier ''cout'' // This program asks for 3 numbers, gives them back, and asks the user if he wants to multiply // it by 5 #include <iostream> int main() { using namespace std; typedef unsigned long int ULONG; ULONG Number_1; ULONG Number_2; ULONG Number_3; ULONG Answer; ULONG Total; cout << "Please type in 3 numbers:" << endl; cout << "Number 1:" << endl; cin >> Number_1; cout << "Number 2:" << endl; cin >> Number_2; cout << "Number 3:" << endl; cin >> Number_3; cout << "The numbers you have entered were: " << Number_1 << Number_2 << Number_3; cout << "Would you like to multiply your answer by 5?" << endl; cout << "Press (1) for yes or (2) for no" << endl; cin >> Total; Answer = (Number_1 + Number_2 + Number_3) * 5; If (Total != ''2'') { cout << "All your Integers added together times 5 is: " << endl; cout << Answer << endl; } Else cout << "Well thank you for testing out my real basic program\n"; return 0; } That''s the code... I''m not sure why it won''t allow me to compile. How can IF be an unideclared identifier?

Share this post


Link to post
Share on other sites
Thanks so much!...

I would really appreciate it if they skipped the Visual Basic aspect of programming. I''m getting used to the non-case sensitive language of Basic.

I have a question. Is that a good C++ program for someone Who''s finished Chapter 4 of 21 in Sams Teach Yourself C++ in 21 Days?

Within these chapters I have learned:
1.What a function is and what it does
2.How the parts work together
3.How to Declare and Define variables and constants.
4.How to assign values to variables and manipulate those values
5.How to write the value of a variable to the screen
6.What statments are
7.What blocks are
8.What expressions are
9.How to branch your code based on conditions
10.What truth is, and how to act on it

That is what I have learned so far, I''m just wondering with that program, am I grasping what I have learned so far?
(btw I didn''t look at the book when i created this program)

Thanks

Share this post


Link to post
Share on other sites
Looks like you know what you''re doing fairly well. Here''s one problem, though:


If (Total != ''2'')


If Total is an unsigned long, you shouldn''t be comparing it to the character ''2''. You should be comparing it to the number two. The above code would not work correctly. Here is the right version:


if (Total != 2)


Another tip is to use better variable names than that. The name ''Total'' has nothing to do with the variable''s function, so it is somewhat confusing to a reader. That''s pretty much all I can think of right now...

Share this post


Link to post
Share on other sites
Thank you guys very much. I plan on reading around 5 C++ books to grasp it well enough to move onto windows.

But for now I hope I'm grasping everything

Awesome fast responses!!! Thanks!!

These books include:
Sams Teach Yourself C++ in 21 Days (I'm reading this now)
Teach Yourself C++ *By Shildt*
Accelerated C++
Effective C++
More Effective C++

Would this be a good choice of books?

[edited by - ThomasSauder on October 2, 2002 9:28:16 PM]

Share this post


Link to post
Share on other sites
Reading so many C++ books is a waste of time as far as I''m concerned. Limit yourself to one beginner book, and a couple of advanced ones. I personally like "The C++ Programming Language" by Bjarne Stroustrup (the original creator of C++). This book is not for beginners though, since it teaches advanced concepts of C++ at a very rapid pace. Some may not agree with me, but I found "Thinking in C++" by Bruce Eckel helpful as well (and besides, you can find it online for free).

Personally, I tend to want to see impressive results from my programs ASAP, so I don''t think it''s necessary to master C++ before moving on to Win32. Once you have a nice, firm grasp of the language, you should be able to pick up Windows and graphics API programming without too much trouble. Of course, you should work on your advanced C++ skills at the same time.

Share this post


Link to post
Share on other sites
quote:
Original post by ThomasSauder
Thanks so much!...

I would really appreciate it if they skipped the Visual Basic aspect of programming. I''m getting used to the non-case sensitive language of Basic.

I have a question. Is that a good C++ program for someone Who''s finished Chapter 4 of 21 in Sams Teach Yourself C++ in 21 Days?

Within these chapters I have learned:
1.What a function is and what it does
2.How the parts work together
3.How to Declare and Define variables and constants.
4.How to assign values to variables and manipulate those values
5.How to write the value of a variable to the screen
6.What statments are
7.What blocks are
8.What expressions are
9.How to branch your code based on conditions
10.What truth is, and how to act on it

That is what I have learned so far, I''m just wondering with that program, am I grasping what I have learned so far?
(btw I didn''t look at the book when i created this program)

Thanks


To answer the question simply, the code is good C++ but it''s flawed. They shouldn''t use "using namespace std", they should teach you to use scopes instead. It tends to make code easier to read...




[Cyberdrek | the last true sorcerer | Spirit Mage - mutedfaith.com]

Share this post


Link to post
Share on other sites
The C++ Programming Language (The book) has gone through many revisions through the years, the 3rd edition (or the special edition based off that one) has all the latest ANSI C++ stuff including STL.

quote:
Original post by ThomasSauder
Isn't The C++ Programming Language out of date? I heard it doesn't even mention STL....




[edited by - deepdene on October 2, 2002 10:14:29 PM]

Share this post


Link to post
Share on other sites