**hi! i need help on fixing this program i made it seems that i can't let it run. Can someone give me some advice on what errors i have made and how i can fix it. thanks **

    #include <iostream.h>
    #include <conio.h>

    void main ()
    {
        int i;
        int j;
        for (i=1;i<=24;i++)
        for (j=1;j<=24;j++)
        {
            if (i%2==1)
            switch(i)
            {
             case 1:
                  cout<<"On the first day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 3:
                  cout<<"On the second day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 5:
                  cout<<"On the third day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 7:
                  cout<<"On the fourth day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 9:
                  cout<<"On the fifth day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 11:
                  cout<<"On the sixth day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 13:
                  cout<<"On the seventh day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 15:
                  cout<<"On the eight day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 17:
                  cout<<"On the ninth day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 19:
                  cout<<"On the tenth day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 21:
                  cout<<"On the eleventh day of christmas\n my true love sent to me:"<<endl;
                  break;
             case 23:
                  cout<<"On the twelfth day of christmas\n my true love sent to me:"<<endl;
                  break;
                  default:
                  break;
            }
        }

            if (j%2==0)
            {
            switch (j)
        {
             case 2:
                  cout<<"A partridge in a pear tree"<<endl;
                  break;
             case 4:
                  cout<<"Two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 6:
                  cout<<"Three french hens\n Two Turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 8:
                  cout<<"Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 10:
                  cout<<"Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 12:
                  cout<<"Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 14:
                  cout<<"Seven swans a-swimming\n Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 16:
                  cout<<"Eight maids a-milking\n Seven swans a-swimming\n Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 18:
                  cout<<"Nine ladies dancing\n Eight maids a-milking\n Seven swans a-swimming\n Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 20:
                  cout<<"Ten lords a-leaping\n Nine ladies dancing\n Eight maids a-milking\n Seven swans a-swimming\n Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 22:
                  cout<<"Eleven pipers piping\n Ten lords a-leaping\n Nine ladies dancing\n Eight maids a-milking\n Seven swans a-swimming\n Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
             case 24:
                  cout<<"Tweleve drummers drumming\n Eleven pipers piping\n Ten lords a-leaping\n Nine ladies dancing\n Eight maids a-milking\n Seven swans a-swimming\n Six geese a-laying\n Five golden rings\n Four calling birds\n Three french hens\n two turtle doves and\n A partridge pear tree"<<endl;
                  break;
                  default:
                  break;
             }
        }
                  getch();


        system("PAUSE");
        return EXIT_SUCCESS;
    }

Recommended Answers

All 7 Replies

copying-paste your errors which you are getting will be helpful. paste your errors or tell me what type of error are you facing ?

here are the errors that appear.

1 C:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31,               from C:\Users\CBS NETZONE\Documents\C++\main.cpp In file included from C:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31,               from C:\Users\CBS NETZONE\Documents\C++\main.cpp 

1 C:\Users\CBS NETZONE\Documents\C++\main.cpp                  from C:\Users\CBS NETZONE\Documents\C++\main.cpp 

32:2 C:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated. 

4 C:\Users\CBS NETZONE\Documents\C++\main.cpp `main' must return `int' 

ok. I will firstky try to remove the errors in the code, then will explain you if you really want to know the reasons.

  1. change line #1 to #include<iostream>
  2. replace void main() with int main()
  3. write a statement "return 0;" (without quotes) at the end of your code, so as to return an integer because main() expects you to return an integer.

  4. EXIT_SUCESS is also okay here, but you can use return 0; also if you want.

make all these changes, and post your doubts here, if you have any. hope it helps. thanks.

it went well but there is another error after i apply some changes

13 C:\Users\CBS NETZONE\Documents\C++\main.cpp `cout' undeclared (first use this function)   (Each undeclared identifier is reported only once for each function it appears in.) 

Use std::cout instead, unless you added the line using namespace std; at the top of your code (after the #includes).

I will say that std is a "thing"(don't know how to explain this word) in which many things are declared. like cout, cin,etc for an instance. you have to mention it's declaration place before using it. so two ways are there.
1. use std::cout at each place instead of cout.
2. Add using namespace std on the top before using any cout, cin.

hope it helps! thanks.

@ nitin1

std is a namespace that all of the standard c++ functions and classes are in. A namespace is just another level of orginizing your code. You can equate it to the file cabinet metaphor. The function is a piece of paper. The file the function is in is a folder. The namespace is the drawer that the folder is in. Your project is the file cabinet that contains it all.

commented: awesome metaphor!! +3
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.