check this code out

This is a discussion on check this code out within the C++ Programming forums, part of the General Programming Boards category; well Trying to learn more I take this challenge, I know its no big deal, but Im putting in practice ...

  1. #1
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112

    Question check this code out

    well
    Trying to learn more I take this challenge,
    I know its no big deal,
    but Im putting in practice the things Ive learned in this bbs
    Ive learn (here) more that ever in class

    Code:
               #include<iostream>
               #include<cstdlib>
               #include<conio.h>
     
               using namespace std;
    
       int main()
    		   {
    		   {
    	int n,data;   
    	cout<<"how many  credits?? :  "<<flush;
    	cin>>n;
                int sum =0;
    system ("cls");  //not quite sure that its the best place 
    		for (int j=0;j<=n,j++)
    			{
    				cin<<data;
    			    sum+=data;  
    			}
       avg = static_cast<float>(sum)/n ; 
      cout<<"Ur average is  :   "<<avg<<endl;  
      cout<<"again??  Y / N"<<flush;
      cin>>op;
     system ("pause");
    	   }while (op!='n');
    	 return 0;
    	   }
    there are all the errors
    Code:
    :\Documents and Settings\Propietario\Mis documentos\C++todo lo que haga\promediogrades.cpp(19) : error C2143: syntax error : missing ';' before ')'
    C:\Documents and Settings\Propietario\Mis documentos\C++todo lo que haga\promediogrades.cpp(21) : error C2676: binary '<<' : 'class std::basic_istream<char,struct std::char_traits<char> >' does not define this operator or a conversion to a type acce
    ptable to the predefined operator
    C:\Documents and Settings\Propietario\Mis documentos\C++todo lo que haga\promediogrades.cpp(24) : error C2065: 'avg' : undeclared identifier
    C:\Documents and Settings\Propietario\Mis documentos\C++todo lo que haga\promediogrades.cpp(27) : error C2065: 'op' : undeclared identifier
    Error executing cl.exe.
    
    promediogrades.exe - 4 error(s), 0 warning(s)
    any idea???
    thx in adv
    love,

    Abyssphobia
    Have I crossed the line?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,496
    Perhaps the next thing to learn is how to format code
    What did you use to indent your code - a random number generator?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Lightbulb

    Here are some things to try....



    1.) for (int j=0;j<=n,j++)

    should be

    for(int j = 0; j <= n; j++) //Use ; semicolons in your for loop structure


    2.) cin<<data;

    should be

    cin >> data; //Use the extraction operator ">>" with 'cin'


    3.) avg = static_cast<float>(sum)/n ;

    could be

    int avg = static_cast<float>(sum)/n ; //Declare the variable "avg" (as in integer) and then intialize it

    **Also, you should look in your book on how to use "set precision" when you are ready to 'cout' a float type variable. Set precision will determine how many decimal places to display.


    cout<<"Ur average is : "<<avg<<endl; //You will need to 'set precision' here.


    4.) cin >> op;

    could be

    char op = 'x'; //delcare the variable and initialize it (to eliminate "garbage data")

    cin >> op; //op can now be used since it has been declared.



    Also, you should try compiling your code using the preprocessor directive #include<conio> instead of #include<conio.h> The ".h" header suffix has been phased out as a c++ standard.

    Hope this helps
    Last edited by The Brain; 08-15-2004 at 04:28 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    101
    >>The ".h" header suffix has been phased out as a c++ standard.
    conio.h is not a standard header, so that change does not apply.

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    you probably want a do before the second { in the following snippet:
    Code:
    int main()
    {
      {

  6. #6
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112
    This is my program and it run perflectly, thx a lot to everyone

    Code:
               #include<iostream>
               #include<cstdlib>
               #include<conio.h>
     
               using namespace std;
    
                int main()
    	   {
    			 
    	         char x ;
    			 
    		   do {
    
    		          int n,data;   
    		
    					  
    			          
    		          cout<<"\n\how many  credits??   "<<flush;
    		          cin>>n;
                        
    		          int sum =0;
    	
    	                   //    system ("cls");
    			
    	                         for (int j=1;j<=n;j++)
    		
                                             {
    		        cout<<"\n grade  "<<j<<"    "; //endl make the grade   be in the line above
    		        cin>>dato;
    			   
    		        sum+=dato;  
    			
    		 }
    			
    		  int avg = static_cast<float>(sum)/n ; 
    			 
    		  cout<<"\n Ur average is  :   "<<avg<<endl;  
    			 
    		  cout<<"\n again??  Y / N"<<flush;
    	
    		  cin>>x;
    			 
    		 system ("pause");
    			   
    		  }while (x!='n');
    		 return 0;
    		   }
    Have I crossed the line?

  7. #7
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Developer Error: Confused by earlier indentation, bailing out.

    You really might want to look into that formatting a bit. It'll be worth it in the long run.

  8. #8
    I'm less than sure.... abyssphobia's Avatar
    Join Date
    Aug 2004
    Posts
    112

    Lightbulb

    Quote Originally Posted by Zach L.
    Developer Error: Confused by earlier indentation, bailing out.

    You really might want to look into that formatting a bit. It'll be worth it in the long run.
    U r rigth,
    Code:
    #include<iostream>
    #include<cstdlib>
    #include<conio.h>
    using namespace std;
    
    int main()
    
      {
    
            char x ;
    			 
    	   do {
    
    	          int n,dato,sum =0;   
                    	  cout<<"\n\nHow much credits :  "<<flush;
    		  cin>>n;
                        
                              for (int j=1;j<=n;j++)
    		
                             {
    		     cout<<"\ngrade/calificacion  "<<j<<"    "; //endl make the grade be in the line above
    		  cin>>dato;
    			   
    		  sum+=dato;  
    			
    	         }
    			
    	        int avg = static_cast<float>(sum)/n ; 
    			 
    	        cout<<"\n Your average is  :   "<<avg<<endl;  
    			 
    	       cout<<"\n again??  Y / N"<<flush;
    	
    	       cin>>x;
    			 
    	       system ("pause");
    	       system ("cls");	   
    	   }while (x!='n');
    	 return 0;
              }
    looks better???, ur opinion is pretty valuable to me???
    regards,
    abyss
    Have I crossed the line?

  9. #9
    Toaster Zach L.'s Avatar
    Join Date
    Aug 2001
    Posts
    2,686
    Gettin' there... Here's my shot at it (clouded with personal preference, of course).
    Code:
    #include<iostream>
    #include<cstdlib>
    #include<conio.h>
    
    using namespace std;
    
    int main()
    {
       char x ;
    
       do
       {
          int n, dato, sum = 0;
    
          cout << "\n\nHow much credits :  " << flush;
          cin >> n;
                        
          for (int j = 1; j <= n; j++)
          {
             cout << "\ngrade/calificacion  " << j << "    "; //endl make the grade be in the line above
             cin >> dato;
             sum += dato;  
          }
    
          int avg = static_cast<float>(sum)/n ; 
    
          cout << "\n Your average is  :   " << avg << endl;  
          cout << "\n again??  Y / N" << flush;
    
          cin >> x;
    
          system("pause");
          system("cls");	   
       } while(x != 'n');
    
       return 0;
    }

  10. #10
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    OOOH I wanna try

    Code:
    #include<iostream>
    #include<cstdlib>
    #include<conio.h>
    
    using namespace std;
    
    int main()
    {
        
        char x ;
    
        do {
          
            int n, dato, sum = 0;
    
            cout << "\n\nHow much credits :  " << flush;
            cin >> n;
                        
            for (int j = 1; j <= n; j++) {
    
                cout << "\ngrade/calificacion  " << j << "    "; //endl make the grade be in the line above
                cin >> dato;
                sum += dato;  
    
            }
    
             int avg = static_cast<float>(sum)/n ; 
    
             cout << "\n Your average is  :   " << avg << endl;  
             cout << "\n again??  Y / N" << flush;
    
             cin >> x;
    
             system("pause");
             system("cls");	
       
       }  while(x != 'n');
    
       return 0;
    
    }
    Theres my monthly dose of spam

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code Check
    By Dae in forum C++ Programming
    Replies: 12
    Last Post: 01-08-2009, 06:01 PM
  2. HELP!!!!emergency ~expert please help
    By unknowppl in forum C Programming
    Replies: 1
    Last Post: 08-19-2008, 07:35 AM
  3. << !! Posting Code? Read this First !! >>
    By kermi3 in forum Game Programming
    Replies: 0
    Last Post: 10-14-2002, 01:27 PM
  4. << !! Posting Code? Read this First !! >>
    By kermi3 in forum C# Programming
    Replies: 0
    Last Post: 10-14-2002, 01:26 PM
  5. Check my code Please
    By AdioKIP in forum C++ Programming
    Replies: 1
    Last Post: 03-12-2002, 07:52 PM

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