Thread: I'm totally a newbie

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    I'm totally a newbie

    Hi to everyone I'm a total newbie but willing to learn, I'm taking Video Game Programming starting January but I want to get ahead since my C++ classes are until next semester so I want to learn some on my own I finished some exercises but this last one can't figure it out
    Code:
    //Programmer: Fernando B
    //Program: debug
    //Purpose: debugging
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int mian ()
    {
        string str = "Hello World!";
    
        cout << str << endl;
    
        cout << float x = 5.0f * str << endl;
    
        int 65Num = 65;
    
        cout << "65Num = " << 65Num << endl;
    
    }
    C:\Users\owner\cpp programmin\exercise 1.6.6 bug fixing.cpp||In function `int mian()':|
    C:\Users\owner\cpp programmin\exercise 1.6.6 bug fixing.cpp|16|error: expected primary-expression before "float"|
    C:\Users\owner\cpp programmin\exercise 1.6.6 bug fixing.cpp|16|error: expected `;' before "float"|
    C:\Users\owner\cpp programmin\exercise 1.6.6 bug fixing.cpp|18|invalid suffix "Num" on integer constant|
    C:\Users\owner\cpp programmin\exercise 1.6.6 bug fixing.cpp|18|error: expected unqualified-id before numeric constant|
    C:\Users\owner\cpp programmin\exercise 1.6.6 bug fixing.cpp|20|invalid suffix "Num" on integer constant|
    ||=== Build finished: 5 errors, 0 warnings ===|

    I spotted a few typos and the mian instead of main, I think the float variable needs to be declared prior to using in cout not quite since the instructions just say run it and try to fix based on the errors. Thanks a lot oh I almost forgot using code::blocks if it matters.

  2. #2
    Registered User
    Join Date
    Dec 2010
    Location
    Australia
    Posts
    8
    Here is a solution to your problem. Please read the in-code comments as they explain the changes that were made to your code.

    Code:
    //Programmer: Fernando B
    //Program: debug
    //Purpose: debugging
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    int main () //Corrected spelling error
    {
    	string str = "Hello World!";
    
    	cout << str << endl;
    
    	//Deprecated/incorrect code
    	//cout << float x = 5.0f * str << endl;
    
    	float x = 5.0f; //Needed to declare the float before outputting it
    
    	cout << x << " " << str << endl; // Unsure how you were trying to output using your previous code but this will output the float followed by a space, followed by a string
        
    	//The compiler does not like it when variables begin with numbers; I changed it to work correctly
    	int Num65 = 65;
    
            cout << "Num65 = " << Num65 << endl;
    
    	//For the sake of seeing the output of the application, we will ask it to pause until a key is pressed
    	system( "pause" );
    
    	//We are within a function (int main) that has a return type. This return type is an integer. Therefore, we must obide and return an int:
    	return 0;
    }
    Good work, but keep practicing! Don't be afraid to try out different things and see what the compiler says (you mentioned that you thought that the float declaration should have been before the output statement; you should have tested it out! Assignments also need to be written before the output statement, not within!) Remember, the compiler is your friend....mostly

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Re: Newest First

    Thanks for the quick reply about this line
    Code:
    //cout << float x = 5.0f * str << endl;
    Do you think that is possible they were trying to multiply the str by the float is that possible? because I honestly don't see what the multiplier operator is doing there.

  4. #4
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Since multiplying five and a string like "Hello World" would not make sense anyway, I think the problem is less about what should have happened, and more about your ability to read compiler digests, and play spot the problem.

    Also, I would like to say that deprecated has a specific meaning unrelated to the word incorrect, and that there is nothing deprecated about that line, or in the entire program.

  5. #5
    Registered User
    Join Date
    Dec 2010
    Location
    Australia
    Posts
    8
    Also, I would like to say that deprecated has a specific meaning unrelated to the word incorrect, and that there is nothing deprecated about that line, or in the entire program.
    I was using the word deprecated in the sense that the line of code:

    Code:
    //Deprecated/incorrect code
    	//cout << float x = 5.0f * str << endl;
    had become obsolete, and was no longer required in the future revisions of the application; it still however, remains valid in the context of the original attempt to get the application to run.

    Am I using the word out of context? I'm sorry that you thought that I was trying to relate the two words, I know that they have distinct definitions. In my haste of providing a solution, I didn't consider the ramifications of using a forward slash, instead of the word and.

    I'm here to learn too, and I would appreciate your opinion
    Thanks

    EDIT: fredz0003, no you can not multiply and float by a string, so it is weird that it was in there in the first place.
    Last edited by LifeInCode; 12-15-2010 at 04:48 AM.

  6. #6
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    You are correct that deprecated is basically another word for obsolete in programming, but deprecated code is still valid code to the compiler (albeit code with all the issues that meet disapproval), so you could still use it.
    Last edited by whiteflags; 12-15-2010 at 09:45 AM.

  7. #7
    Registered User
    Join Date
    Dec 2010
    Posts
    10

    Wink Re: Newest First

    Got it thank you guys for your help.

  8. #8
    Registered User
    Join Date
    Dec 2010
    Location
    Australia
    Posts
    8
    No worries

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. newbie: array question :(
    By cstudent in forum C Programming
    Replies: 2
    Last Post: 04-09-2008, 06:46 AM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 12:53 PM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Totally newbie to grafic
    By Zahl in forum Game Programming
    Replies: 3
    Last Post: 11-12-2002, 03:16 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM