Many Error Messages in my C++ Program
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Many Error Messages in my C++ Program

  1. #1
    Join Date
    Mar 2011
    Posts
    9

    Many Error Messages in my C++ Program

    I am new to programming and don't know what is wrong. I've tried to fix it for about a day now.
    #include <iostream>
    #include <string>

    int main ()

    {
    using std::cout;
    using std::cin;
    using std::string;
    string enter = "";
    int gold;
    int number;
    int america;
    int newgold;
    int twogold, city, threegold;

    cout << "Welcome to the coin game. "
    << "The objective is to get 1000 coins by the end.\n"
    << "(Press 1 and hit enter to continue.)\n";

    cin >> enter;

    cout << "\nFirst, solve 432 * 23, "
    << "in order to get your first 50 coins "
    << "(no calculators!).\n";
    cin >> number;
    if (number != 9936)
    cout << "Sorry, you do not get 50 coins.";
    else {
    cout << "Congratulations, you now have 50 coins!";
    gold = 0 + 50;

    }
    cout << " The next test is to figure out how old America is as of 2011.\n"
    << " (worth 75 coins.)\n";
    cin >> america;

    if ( america != 235 ) {
    cout << "Sorry, you do not get 75 coins.\n"
    << "You have "
    << gold
    << " coins.";
    }
    else {
    cout << "Congratulations, you now have "
    << (gold + 75)
    << " coins!\n";
    newgold = gold + 75;
    }
    cout << "Now for your next question.\n"
    << "What is N.Y. City's approximate population?";
    cin >> city;

    if (city != 8000000)
    twogold = newgold + 0;
    cout << "Sorry, you do not get 75 coins.\n"
    << "You still have "
    << twogold
    << " coins.";

    else { // Error: Expected '}' before 'else'.
    cout << "Congratulations, you now have "
    << twogold = newgold + 75;
    << " coins.";
    }
    using std::cout;
    using std::cin;
    cout << "This next question is worth 200 coins!\n"
    // Error: Expected constructor, destructor, or type conversion before '<<' token.
    << "How old would Martin Luther King Jr. "
    << "be as of January 1, 2011?";
    cin >> king; // Error: Expected constructor, destructor, or type conversion before '>>' token.

    if (king != 0 ) // Error: Expected unqualified-id before 'if'.
    threegold = twogold + 0
    cout << "Yikes! " // Error: Expected constructor, destructor, or type conversion before '<<' token.
    << "You do not get 200 coins.\n"
    << "You still have "
    << threegold
    << " coins."

    else {
    threegold = twogold + 200
    cout << "Congratulations, you get 200 coins!"
    << "You now have "
    << threegold
    << " coins."
    }


    return 0; // Error: Expected unqualified-id before return.

    } // Error: Expected declaration before '}' token.

  2. #2
    Join Date
    Jan 2006
    Location
    Berlin, Germany
    Posts
    405

    Re: Many Error Messages in my C++ Program

    If you have more than one statement after the if condition you need to surround it by braces.

    Code:
    if (condition) {
      // Statement 1...
      // Statement 2...
    }
    At least your first else doesn't match because of that apparently.

  3. #3
    Join Date
    Mar 2011
    Posts
    9

    Re: Many Error Messages in my C++ Program

    Quote Originally Posted by ltcmelo View Post
    If you have more than one statement after the if condition you need to surround it by braces.

    Code:
    if (condition) {
      // Statement 1...
      // Statement 2...
    }
    At least your first else doesn't match because of that apparently.
    Thanks. That seemed to fix it. But do you know how to make my code into an application? Or is that too complicated for you to tell me?

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Many Error Messages in my C++ Program

    But this is an application, it's a Win32 console application. Right? Do you mean you want an application with a GUI? In this case you'd have to describe how it should look and what to do. But you probably want to create an MFC dialog based application.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Mar 2011
    Posts
    9

    Re: Many Error Messages in my C++ Program

    Quote Originally Posted by cilu View Post
    Describe how it should look and what to do. But you probably want to create an MFC dialog based application.
    Yes, I do want a GUI. With a basic white background and the words to be in a corner as a chat type thing.

  6. #6
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Many Error Messages in my C++ Program

    Quote Originally Posted by prattcmp View Post
    Yes, I do want a GUI. With a basic white background and the words to be in a corner as a chat type thing.
    In that case you need to create a new project.

  7. #7
    Join Date
    Mar 2011
    Posts
    9

    Re: Many Error Messages in my C++ Program

    Quote Originally Posted by Skizmo View Post
    In that case you need to create a new project.
    Umm. That doesn't really help much. Explain a bit further please?

  8. #8
    Join Date
    Apr 2008
    Posts
    726

    Re: Many Error Messages in my C++ Program

    your (linker) subsystem is console. If you want a gui using windows messages event loop, you need to change the subsystem, or create a new studio project (win32 project) with better defaults. This will give you a WinMain or _tWinMain (or similar), instead of your current main().

  9. #9
    Join Date
    Sep 2004
    Location
    Holland (land of the dope)
    Posts
    4,123

    Re: Many Error Messages in my C++ Program

    Quote Originally Posted by prattcmp View Post
    Umm. That doesn't really help much. Explain a bit further please?
    Create a new project with the Visual Studio and you will see that you have the option (amongst other project types) to create a console program (what you have now) and you can create a GUI program (MFC).

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center