Like Tree13Likes

Questions about this program in c++

This is a discussion on Questions about this program in c++ within the C++ Programming forums, part of the General Programming Boards category; #include <iostream> // no .h And please stop using `void main`. `int main` is one of the correct forms....

  1. #16
    Registered User
    Join Date
    Aug 2010
    Location
    Poland
    Posts
    682
    #include <iostream> // no .h

    And please stop using `void main`. `int main` is one of the correct forms.
    I never put signature, but I decided to make an exception.

  2. #17
    Registered User
    Join Date
    Jun 2011
    Posts
    2,690
    Well, that's funny. You didn't add the closing brace after the loop like I said (I even gave you the line number).
    Nor did you take the advice in post #8 about "main()" returning an int, not void.
    Salem likes this.

  3. #18
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by kmdv View Post
    #include <iostream> // no .h

    And please stop using `void main`. `int main` is one of the correct forms.
    Having .h is not an error. But it should be good to follow this tip.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #19
    Registered User
    Join Date
    Jan 2013
    Posts
    23
    Did not work, my friend began to despair

  5. #20
    Registered User
    Join Date
    Jun 2011
    Posts
    2,690
    Indeed.

    Code:
    Me:  "The answer to question #4 is 'B'."
    
    You: "How do I work this pencil?"

  6. #21
    Registered User
    Join Date
    Jan 2013
    Posts
    23
    Excuse me I'm sorry because I am new to the language c

  7. #22
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    ok, post the updated code
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #23
    Registered User
    Join Date
    Jun 2011
    Posts
    2,690
    Quote Originally Posted by man silence View Post
    Excuse me I'm sorry because I am new to the language c
    That's fine, but we have not even gotten to any programming related advice. We're trying to start by making sure the code you posted has the correct syntax so you can compile it. I told you exactly what to type, in the exact location, and you didn't even get that far.

    When you hit a roadblock like this, the best thing to do is take a step back. Go back to what you know, review what you've learned, and try going forward again slowly, making sure you understand each small step.

    It's a bit suspicious that you claim you created* this code, but can't figure out that a brace is missing (especially when it was pointed out explicitly in this thread).


    (*) I'll give you credit that you said "create" this code, and not "write" this code, because it is obviously a copy/paste mish-mosh of code written by others (i.e. here).
    Salem likes this.

  9. #24
    Registered User
    Join Date
    Jan 2013
    Posts
    23
    This is the last update and there is one error


    unexpected end of file found


    Code:
    #include<iostream.>
     using namespace std;
    int main()
    {
        float x,y,r;
        const double p=3.14;
        double area;                 
        float a,b;
        float d;
        int choes;
      
        do {
            cout<<"[simple porogram]"<<endl;
            cout<<" ==============="<<endl;
            cout<<"main menu"<<endl;
            cout<<"========="<<endl;
            cout<<" Enter the number (1) to calculate area and vicinity of rectangle . "<<endl;
            cout<<" Enter the number (2) to calculate area and vicinity of circle . "<<endl;
            cout<<" Enter the number (3) to calculate area of triangle . "<<endl;
            cout<<" Enter the number (4) to calculate  vicinity of triangle . "<<endl;
            cout<<" Enter the number (5) to calculate area and vicinity of square . "<<endl;
            cout<<" Enter the number (6) to drow a rectangle ."<<endl;
            cout<<" Enter the number (7) to drow a triangle ."<<endl;
            cout<<" Enter the number (8) to drow diamond."<<endl;
            cout<<" ===================================="<<endl;
            cout<<" Enter the number :"<<endl;
      
            cin>>choes;
      
            switch (choes)
            {
                case 1:   
                    cout<<"enter the length  : ";
                    cin>>x;
                    cout<<"enter the width :";
                    cin>>y;
                    cout<<"the area of rectangle is :"<<x*y<<endl;
                    cout<<"the vicinity of rectangle is :"<<(x+y)*2<<endl;
                    break ;
                case 2:
                    cout<<"enter the radius :"<<endl;
                    cin>>r;
                    area=(r*r)*p;
                    cout<<"the area of circle is :"<<area<<endl;
                    cout<<"the vicinity of circle is :"<<(r*p)*2<<endl;
                    break;
                case 3:
                    cout<<"Enter the hight and base :"<<endl;
                    cin>>a>>b;
                    cout<<"the area of triangle is :"<<0.5*a*b<<endl;
                    break;
                case 4:
                    cout<< "Enter lengths ribs :"<<endl;
                    cin>>a>>b>>d;
                    cout<< "the vicinity of triangle is :"<<a+b+d<<endl;
                    break;
                case 5:
                    cout<<"Enter the length of the rib :   "<<endl;
                    cin>>d,
                    cout<<"the area of square is :"<<d*d<<endl;
                    cout<<"the vicinity of square is :"<<d*4<<endl;
                    break;
                case 6:
                    {
                        for(int z=1; z<=79; z++)
                        {
                            cout << "*";
                        }
                        cout << endl;
     
                        for(int i=1; i<=10; i++)
                        {
                            cout << "*";
                            for(int j=1; j<=77; j++)
                            {
                                cout << " ";
                            }
                            cout << "*" << endl;
                        }
     
                        for(int y=1; y<=79; y++)
                        {
                            cout << "*";
                        }
                        cout << endl;
                    }
                    break;
                case 7:
                    {
                        for (int a = 1; a <= 20; a++)
                        {
                            for (int i = 1; i <= a; i++)
                                cout << "*";
                            cout << endl;    
                        }
                    cout << endl;
                    }
                    break ;
                case 8:
                    cout << "      * \n    * * *\n   * * * *\n  * * * * *\n * * * * * *\n* * * * * * *\n * * * * * *\n  * * * * *\n   * * * *\n    * * *\n      * \n";
                    break;
                default :
                    cout<<" error "<<endl;
                    cout<<" (wrong  choice) "<<endl;
     
            while ( choes != 0 );
            }
        }

  10. #25
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Write this
    Code:
    #include<iostream.>
    as this
    Code:
    #include<iostream>
    and insert a right bracket } in line 106, like this
    Code:
    }while ( choes != 0 );
    But, Matticus is right.....
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  11. #26
    Registered User
    Join Date
    Jan 2013
    Posts
    23
    the same last error


    Code:
    #include<iostream>
     using namespace std;
    int main()
    {
        float x,y,r;
        const double p=3.14;
        double area;                
        float a,b;
        float d;
        int choes ;
       
        do {
            cout<<"[simple porogram]"<<endl;
            cout<<" ==============="<<endl;
            cout<<"main menu"<<endl;
            cout<<"========="<<endl;
            cout<<" Enter the number (1) to calculate area and vicinity of rectangle . "<<endl;
            cout<<" Enter the number (2) to calculate area and vicinity of circle . "<<endl;
            cout<<" Enter the number (3) to calculate area of triangle . "<<endl;
            cout<<" Enter the number (4) to calculate  vicinity of triangle . "<<endl;
            cout<<" Enter the number (5) to calculate area and vicinity of square . "<<endl;
            cout<<" Enter the number (6) to drow a rectangle ."<<endl;
            cout<<" Enter the number (7) to drow a triangle ."<<endl;
            cout<<" Enter the number (8) to drow diamond."<<endl;
            cout<<" ===================================="<<endl;
            cout<<" Enter the number :"<<endl;
       
            cin>>choes;
       
            switch (choes)
            {
                case 1:  
                    cout<<"enter the length  : ";
                    cin>>x;
                    cout<<"enter the width :";
                    cin>>y;
                    cout<<"the area of rectangle is :"<<x*y<<endl;
                    cout<<"the vicinity of rectangle is :"<<(x+y)*2<<endl;
                    break ;
                case 2:
                    cout<<"enter the radius :"<<endl;
                    cin>>r;
                    area=(r*r)*p;
                    cout<<"the area of circle is :"<<area<<endl;
                    cout<<"the vicinity of circle is :"<<(r*p)*2<<endl;
                    break;
                case 3:
                    cout<<"Enter the hight and base :"<<endl;
                    cin>>a>>b;
                    cout<<"the area of triangle is :"<<0.5*a*b<<endl;
                    break;
                case 4:
                    cout<< "Enter lengths ribs :"<<endl;
                    cin>>a>>b>>d;
                    cout<< "the vicinity of triangle is :"<<a+b+d<<endl;
                    break;
                case 5:
                    cout<<"Enter the length of the rib :   "<<endl;
                    cin>>d,
                    cout<<"the area of square is :"<<d*d<<endl;
                    cout<<"the vicinity of square is :"<<d*4<<endl;
                    break;
                case 6:
                    {
                        for(int z=1; z<=79; z++)
                        {
                            cout << "*";
                        }
                        cout << endl;
      
                        for(int i=1; i<=10; i++)
                        {
                            cout << "*";
                            for(int j=1; j<=77; j++)
                            {
                                cout << " ";
                            }
                            cout << "*" << endl;
                        }
      
                        for(int y=1; y<=79; y++)
                        {
                            cout << "*";
                        }
                        cout << endl;
                    }
                    break;
                case 7:
                    {
                        for (int a = 1; a <= 20; a++)
                        {
                            for (int i = 1; i <= a; i++)
                                cout << "*";
                            cout << endl;   
                        }
                    cout << endl;
                    }
                    break ;
                case 8:
                    cout << "      * \n    * * *\n   * * * *\n  * * * * *\n * * * * * *\n* * * * * * *\n * * * * * *\n  * * * * *\n   * * * *\n    * * *\n      * \n";
                    break;
                default :
                    cout<<" error "<<endl;
                    cout<<" (wrong  choice) "<<endl;
      
            } while ( choes != 0 );
            
        }

  12. #27
    Registered User
    Join Date
    Jun 2011
    Posts
    2,690
    Now you're starting to look like a troll.

    Count the opening braces in your code ( { ).
    Count the closing braces in your code ( } ).

    Tell us how many of each you have.
    Salem and Elysia like this.

  13. #28
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    As I said about the switch cases in a previous post, do the following :
    1 - Remove the brackets from case 6 (line 64 and 86)
    2 - Remove the brackets from case 7 (line 89 and 97)
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  14. #29
    Registered User
    Join Date
    Jan 2013
    Posts
    23
    Done that gave me 12 error
    I will try later
    Thank you
    good night
    D:\c++\rrrrrrrrrrr.cpp(88) : error C2360: initialization of 'y' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(81) : see declaration of 'y'
    D:\c++\rrrrrrrrrrr.cpp(88) : error C2360: initialization of 'i' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(71) : see declaration of 'i'
    D:\c++\rrrrrrrrrrr.cpp(88) : error C2360: initialization of 'z' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(65) : see declaration of 'z'
    D:\c++\rrrrrrrrrrr.cpp(99) : error C2360: initialization of 'a' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(90) : see declaration of 'a'
    D:\c++\rrrrrrrrrrr.cpp(99) : error C2360: initialization of 'y' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(81) : see declaration of 'y'
    D:\c++\rrrrrrrrrrr.cpp(99) : error C2360: initialization of 'i' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(71) : see declaration of 'i'
    D:\c++\rrrrrrrrrrr.cpp(99) : error C2360: initialization of 'z' is skipped by 'case' label
    D:\c++\rrrrrrrrrrr.cpp(65) : see declaration of 'z'
    D:\c++\rrrrrrrrrrr.cpp(102) : error C2361: initialization of 'a' is skipped by 'default' label
    D:\c++\rrrrrrrrrrr.cpp(90) : see declaration of 'a'
    D:\c++\rrrrrrrrrrr.cpp(102) : error C2361: initialization of 'y' is skipped by 'default' label
    D:\c++\rrrrrrrrrrr.cpp(81) : see declaration of 'y'
    D:\c++\rrrrrrrrrrr.cpp(102) : error C2361: initialization of 'i' is skipped by 'default' label
    D:\c++\rrrrrrrrrrr.cpp(71) : see declaration of 'i'
    D:\c++\rrrrrrrrrrr.cpp(102) : error C2361: initialization of 'z' is skipped by 'default' label
    D:\c++\rrrrrrrrrrr.cpp(65) : see declaration of 'z'
    D:\c++\rrrrrrrrrrr.cpp(109) : fatal error C1004: unexpected end of file found
    Error executing cl.exe.

    rrrrrrrrrrr.exe - 12 error(s), 0 warning(s)




    Code:
    #include<iostream>
     using namespace std;
    int main()
    {
        float x,y,r;
        const double p=3.14;
        double area;                
        float a,b;
        float d;
        int choes ;
        
        do {
            cout<<"[simple porogram]"<<endl;
            cout<<" ==============="<<endl;
            cout<<"main menu"<<endl;
            cout<<"========="<<endl;
            cout<<" Enter the number (1) to calculate area and vicinity of rectangle . "<<endl;
            cout<<" Enter the number (2) to calculate area and vicinity of circle . "<<endl;
            cout<<" Enter the number (3) to calculate area of triangle . "<<endl;
            cout<<" Enter the number (4) to calculate  vicinity of triangle . "<<endl;
            cout<<" Enter the number (5) to calculate area and vicinity of square . "<<endl;
            cout<<" Enter the number (6) to drow a rectangle ."<<endl;
            cout<<" Enter the number (7) to drow a triangle ."<<endl;
            cout<<" Enter the number (8) to drow diamond."<<endl;
            cout<<" ===================================="<<endl;
            cout<<" Enter the number :"<<endl;
        
            cin>>choes;
        
            switch (choes)
            {
                case 1:  
                    cout<<"enter the length  : ";
                    cin>>x;
                    cout<<"enter the width :";
                    cin>>y;
                    cout<<"the area of rectangle is :"<<x*y<<endl;
                    cout<<"the vicinity of rectangle is :"<<(x+y)*2<<endl;
                    break ;
                case 2:
                    cout<<"enter the radius :"<<endl;
                    cin>>r;
                    area=(r*r)*p;
                    cout<<"the area of circle is :"<<area<<endl;
                    cout<<"the vicinity of circle is :"<<(r*p)*2<<endl;
                    break;
                case 3:
                    cout<<"Enter the hight and base :"<<endl;
                    cin>>a>>b;
                    cout<<"the area of triangle is :"<<0.5*a*b<<endl;
                    break;
                case 4:
                    cout<< "Enter lengths ribs :"<<endl;
                    cin>>a>>b>>d;
                    cout<< "the vicinity of triangle is :"<<a+b+d<<endl;
                    break;
                case 5:
                    cout<<"Enter the length of the rib :   "<<endl;
                    cin>>d,
                    cout<<"the area of square is :"<<d*d<<endl;
                    cout<<"the vicinity of square is :"<<d*4<<endl;
                    break;
                case 6:
                    
                        for(int z=1; z<=79; z++)
                        {
                            cout << "*";
                        }
                        cout << endl;
       
                        for(int i=1; i<=10; i++)
                        {
                            cout << "*";
                            for(int j=1; j<=77; j++)
                            {
                                cout << " ";
                            }
                            cout << "*" << endl;
                        }
       
                        for(int y=1; y<=79; y++)
                        {
                            cout << "*";
                        }
                        cout << endl;
                    
                    break;
                case 7:
                    
                        for (int a = 1; a <= 20; a++)
                        {
                            for (int i = 1; i <= a; i++)
                                cout << "*";
                            cout << endl;   
                        }
                    cout << endl;
                    
                    break ;
                case 8:
                    cout << "      * \n    * * *\n   * * * *\n  * * * * *\n * * * * * *\n* * * * * * *\n * * * * * *\n  * * * * *\n   * * * *\n    * * *\n      * \n";
                    break;
                default :
                    cout<<" error "<<endl;
                    cout<<" (wrong  choice) "<<endl;
       
            } while ( choes != 0 );
             
        }

  15. #30
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Those last few bracekts you were told to remove need to be put back because you are using an old compiler that does not respect the new standard on for-loop variable scoping.

    You are using various wrong wrong words and bad spelling in there. Rather than "vicinity", you actually mean "perimeter". And instead of "ribs" you mean "sides". "height" is spelt with an 'e', and "draw" is spelt with an 'a'.

    Your terrible approximation of Pi will give you a bad result too.

    There is still one missing curly bracket. Figure out what each bracket matches with and you should be able to see the problem.
    stahta01 likes this.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help!!!questions about a circuit program..
    By vivian_4658 in forum C++ Programming
    Replies: 2
    Last Post: 12-10-2011, 12:06 PM
  2. 2 simple C program questions.
    By justiliang in forum C Programming
    Replies: 5
    Last Post: 10-27-2011, 01:59 AM
  3. First program questions
    By spottedzebra in forum C Programming
    Replies: 7
    Last Post: 06-18-2010, 10:34 AM
  4. A program that kills itself...and questions
    By Shadow in forum C Programming
    Replies: 5
    Last Post: 07-25-2002, 08:08 PM
  5. My first program (and a few questions)
    By elfjuice in forum C++ Programming
    Replies: 15
    Last Post: 05-28-2002, 05:30 PM

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