NEED help!!

This is a discussion on NEED help!! within the C++ Programming forums, part of the General Programming Boards category; Code: Im new to C++ programming Im using Visual C++2008.. this is my program.. #include "stdafx.h" #include <iostream> #include <stdlib.h> ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    20

    NEED help!!

    Code:
    Im new to C++ programming 
     Im using Visual C++2008.. this is my program.. 
    
    
    #include "stdafx.h"
    #include <iostream>
    #include <stdlib.h>
    
    
    #include <stdio.h>
    #include<limits>
    
    
    
    
    
    void main()
    int option =3;
    switch (option)
    {
    case 1:cout<<"one";
    	break;
    case 2:cout<<"two";
    	break;
    case 3:cout<< "three";
    	break;
    default: cout<<"no value";
    	system("pause");
    
    }
    .... but it doesnt work :( These errors comes... I wanna know why
    
    
    Error	1	error C2144: syntax error : 'int' should be preceded by ';'	
    Error	2	error C2059: syntax error : 'switch'	
    Error	3	error C2143: syntax error : missing ';' before '{'	
    Error	4	error C2447: '{' : missing function header (old-style formal list?)	
    
    
     do I need to include another header file?? please tell me whats wrong :( I have no clue :(

  2. #2
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,649
    First, it's not void main() it's int main(), always!

    Second, where are the {}s around your main? It's

    Code:
    int main()
    {  // start main code
       
        // Code here
        
    }// end main code
    This should have been the very first page of your text. And why are you including <stdio.h>? It's not necessary.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by thili View Post
    [code]
    Im new to C++ programming
    Im using Visual C++2008.. this is my program..
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <stdlib.h>
    #include <stdio.h>
    #include<limits>
    
    void main()
    {
       int option =3;
       switch (option)
       {
         case 1:cout<<"one";
            break;
         case 2:cout<<"two";
            break;
         case 3:cout<< "three";
            break;
         default: cout<<"no value";
            system("pause");
       }
    }
    do I need to include another header file?? please tell me whats wrong I have no clue
    Nope... just watch your brace matching.

  4. #4
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Quote Originally Posted by rags_to_riches View Post
    First, it's not void main() it's int main(), always!

    Second, where are the {}s around your main? It's

    Code:
    int main()
    {  // start main code
       
        // Code here
        
    }// end main code
    This should have been the very first page of your text. And why are you including <stdio.h>? It's not necessary.
    Thanks alot.. but now this error comes :/
    Error 1 error C2065: 'cout' : undeclared identifier........... I included std thing in header ..

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Quote Originally Posted by CommonTater View Post
    Code:
    #include "stdafx.h"
    #include <iostream>
    #include <stdlib.h>
    #include <stdio.h>
    #include<limits>
    
    void main()
    {
       int option =3;
       switch (option)
       {
         case 1:cout<<"one";
            break;
         case 2:cout<<"two";
            break;
         case 3:cout<< "three";
            break;
         default: cout<<"no value";
            system("pause");
       }
    }

    Nope... just watch your brace matching.

    Thanks a lot but now this error comes Error 1 error C2065: 'cout' : undeclared identifier I included std thing in the header

  6. #6
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    yaa its working .. Thank you very much every!!
    thanks loaads!! I have deleted std thing accidently.. now only i saw it :P
    ooopz.. thankyou very much guys

  7. #7
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by thili View Post
    Thanks a lot but now this error comes Error 1 error C2065: 'cout' : undeclared identifier I included std thing in the header
    Try adding using namespace std just under your includes.

  8. #8
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Quote Originally Posted by CommonTater View Post
    Try adding using namespace std just under your includes.
    thanks alot ya now its working

  9. #9
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by thili View Post
    thanks alot ya now its working
    Glad I could help... I'm just learning C++ myself and I don't even want to guess how often I've tripped over that namespace thing...

  10. #10
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Code:
    #include "stdafx.h"
    #include <iostream>
    
    #include<limits>
    using namespace std;
    
    void main()
    {
    	char letter;
    	cin >> letter;
    	switch (letter)
    	{
    	        case a: cout <<"vowel";
    		     break;
    			case e: cout <<"vowel";
    				break;
    			case i: cout <<"vowel";
    				break;
    			case o: cout <<"vowel";
    				break;
    			case u: cout <<"vowel";
    				break;
    	default: cout << "not a vowel"<<endl;
    	}
    	
    }
    WHATS WRONG WITH THIS PROGRAM?>? ((((((((

  11. #11
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by thili View Post
    Code:
    #include "stdafx.h"
    #include <iostream>
    
    #include<limits>
    using namespace std;
    
    void main()
    {
    	char letter;
    	cin >> letter;
    	switch (letter)
    	{
    	        case a: cout <<"vowel";
    		     break;
    			case e: cout <<"vowel";
    				break;
    			case i: cout <<"vowel";
    				break;
    			case o: cout <<"vowel";
    				break;
    			case u: cout <<"vowel";
    				break;
    	default: cout << "not a vowel"<<endl;
    	}
    	
    }
    WHATS WRONG WITH THIS PROGRAM?>? ((((((((
    It's in the way you've set up your switch... a is a variable... 'a' is a character...

  12. #12
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Error 1 error C2065: 'a' : undeclared identifier
    Error 2 error C2051: case expression not constant
    Error 3 error C2065: 'e' : undeclared identifier
    Error 4 error C2051: case expression not constant
    like that same errors come up to u
    Error 10 error C2051: case expression not constant

    Warning 11 warning C4065: switch statement contains 'default' but no 'case' labels

  13. #13
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Quote Originally Posted by CommonTater View Post
    It's in the way you've set up your switch... a is a variable... 'a' is a character...
    so what do I need to to do.. create variable s for a-i??

  14. #14
    Registered User
    Join Date
    Jan 2011
    Posts
    20
    Quote Originally Posted by CommonTater View Post
    It's in the way you've set up your switch... a is a variable... 'a' is a character...
    Its working thanks a lot for your help

  15. #15
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    You need to read a book about the language instead of posting every single error you get here and having others fix them.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

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