Problem with for loop

This is a discussion on Problem with for loop within the C++ Programming forums, part of the General Programming Boards category; Hello. I am having a problem with a program I am making. It won't compile. Can somebody look at it ...

  1. #1
    Registered User
    Join Date
    Sep 2006

    Post Problem with for loop

    Hello. I am having a problem with a program I am making. It won't compile. Can somebody look at it and see what I am doing wrong? (it says that there is a problem with the for loop)
    #include <cstdlib>
    #include <iostream>
    #include <string>
    #include <windows.h>
    #include <fstream>
    using namespace std;
    int mainmenu () {
         cout<< "Welcome to the NaNoWriMo Notepad!\nHave fun!\n";
        cout<< "\nMAIN MENU\n 1 Create a New Project\n 2 Open a Project\n 3 quit\n\n";
        int mainmenu;
        cin>> mainmenu;
    void create () {
          cout<< "What is your project's name (you can't change this later) (hint: you need to rememer this, so call it the year): ";
                    char filename[20];
                    cin>> filename;
                    cout<< "\nYour file is called " << filename << "\n";
                    cout<< "Your file is now being created.\n";
                                ofstream Project(filename, ios::out);
    int main(int argc, char *argv[])
        ofstream fout;
        system("color 02"); 
        SetConsoleTitle("NaNoWriMo Notepad");
    for(,,) {
        int menu;
        menu = mainmenu();
        if(menu == 1) {
                create ();               
        else if(menu == 2) {
             char myfile[20];
             cout<< "Enter the name of your file (the year): ";
             cin>> myfile;
        else if(menu == 3) {
        cout<<"Hello World!\n";
        string test;
        getline( cin, test );
        cout<< test;
        return EXIT_SUCCESS;

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    should be

    although it should really be a while loop.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    pwns nooblars
    Join Date
    Oct 2005
    Portland, Or
    Well first lets look at this code and what can be gotten rid of... such as the whole cout<<"Hello World"

    You are trying to make an infinate loop with for(,,) but you got it wrong, you want for(; but generally if you need to do that in small basic programs you are doing something wrong design wise.

    Perhaps you can make a variable (bool run = true) then have a while(run) loop instead of the for loop. That way you don't have to make a call to system("exit") which is another frowned on programming practice.

    [edit] 99% of times system() calls can be completely avoided, don't use them unless you have a REALLY good reason to. You could just replace system("exit"); with return 0; and get the same results. Only the return 0; Allows the program to exit naturally.
    Last edited by Wraithan; 09-29-2006 at 04:22 PM.

  4. #4
    Registered User
    Join Date
    Sep 2006
    Oh, thanks! I knew it was something simple...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 04:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 10:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21