Thread: some question asking for answer...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    11

    Talking some question asking for answer...

    hi, I'm not "old" in this stuff c++ but, I got some problems.
    first. how do I execute 1 of the files in 1 project. 1 is int main() and 1 is int submain() so how do I execute only the int submain()?

    2nd.What pointers and structures are meant for?

    3rd.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    11
    oh and y does this:
    Code:
     #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
      int y;
      int array[8][8]; // Declares an array like a chessboard
      
      for ( x = 0; x < 8; x++ ) {
        for ( y = 0; y < 8; y++ )
          array[x][y] = x * y; // Set each element to a value
      }
      cout<<"Array Indices:\n";
      for ( x = 0; x < 8;x++ ) {
        for ( y = 0; y < 8; y++ )
          cout<<"["<<x<<"]["<<y<<"]="<< array[x][y];
    	cout<<"\n";
      }
      cin.get();
    }
    different of this:
    Code:
     #include <iostream>
    
    using namespace std;
    
    int main()
    {
      int x;
      int y;
      int array[8][8]; // Declares an array like a chessboard
      
      for ( x = 0; x < 8; x++ ) {
        for ( y = 0; y < 8; y++ )
          array[x][y] = x * y; // Set each element to a value
      }
      cout<<"Array Indices:\n";
      for ( x = 0; x < 8;x++ ) {
        for ( y = 0; y < 8; y++ )
          cout<<"["<<x<<"]["<<y<<"]="<< array[x][y]"\n";
      }
      cin.get();
    }
    Note the cout<<"\n";
    and the cout<<"["<<x<<"]["<<y<<"]="<< array[x][y]"\n";

    the first 1, when they're separated, it shows the results clearly and 'endl' only after a whole [8] array only then it ends the line, but the 2nd ends the line every result. (indices).

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    this

    array[x][y]"\n";

    should not compile...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    You already asked the first question. If the answers were not good enough, may-be you should provide more information, for example show the code.

    The second question is a bit too open-ended. It almost sounds like 'I've heard there are pointers and structs, should I bother to learn what they are?' Yes, you should and in the course you would probably find out yourself what they are good for.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Apr 2008
    Posts
    11
    ok cool anyway heres the code of the 2 file 1 project:
    Code:
     #include <iostream>
    
    using namespace std;
    
    int main()
    { char act;
    
    	do {
    	cout<<"Please choose 1 of a mathematic actions. For multiplying press m, divide - d, add - a, and less - l ";
    	cin>> act;
    	int num, num1;
    	switch (act) {
    		case 'm':
    	cout<<"Input 2 numbers to be multiplied(press enter after u choose the one and after the another) \n";
    	cin>> num;
    	cin.ignore();
    	cout<<" x \n";
    	cout<< endl;
    	cin>> num1;
    	cin.ignore();
    	cout<<"= "<< num * num1;
    	cin.get();
    	break;
    	return 0;
    		case 'd':
    			cout<<"Input 2 numbers to be divide\n";cin.ignore();
    			cin>> num; cin.ignore(); 
    			cout<<" : "; 
    			cin>> num1; 
    			cin.ignore();
    			cout<<" = "<< num / num1;
    			cin.get();
    			break;
    			return 0;
    		case 'a':
    			cout<<"Input 2 numbers u choose to add to each one\n";
    			cin>> num; cin.ignore(); cout<<" + "; cin>> num1;
    			cin.ignore();
    			cout<<" = "<< num + num1;
    			break;
    			return 0;
    			cin.get();
    		case 'l':
    			cout<<"Input 2 numbers to calculate the first minus the 2nd \n";
    				cin>> num;
    			cin.ignore();
    			cout<<" - ";
    			cin>> num1;
    			cin.ignore();
    			cout<<" = ";
    			cin.ignore();
    			cout<<num - num1;
    			cin.get();
    			return 0;
    	} 
    	} while(!(act == 'm' || act == 'd' || act == 'a' || act == 'l'));
    }
    this was my first 1, with the int main() now heres the 2nd:
    Code:
     #include <iostream>
    
    using namespace std;
    
    int submain()
    {
    
      int x;            // A normal integer
      int *p;           // A pointer to an integer
      p = &x;           // Read it, "assign the address of x to p"
      cin>> x;          // Put a value in x, we could also use *p here
      cin.ignore();
      cout<< *p <<"\n"; // Note the use of the * to get the value
      cin.get();
      return 0;
    
    }
    Last edited by mat13mat; 04-30-2008 at 03:22 AM.

  6. #6
    The larch
    Join Date
    May 2006
    Posts
    3,573
    These are two separate programs? May-be it seems to you like one project but if both files are not part of the same program it is not the same project.

    Replace submain with main and compile it as a separate program/project?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  7. #7
    Registered User
    Join Date
    Apr 2008
    Posts
    11
    oh another thing is: when I execute a file or a project, I think it might build everything then run the .exe file, now the .exe file suppose to be saved somewhere, where is it? I use microsoft visual c++ 2008, I open my documents, visual c++ 2008\projects\"the name of my project"\Debug\ <-- there I think the file suppose to be, and I cant find it, all I see is .res things, . pdb(project debug base)... but no .exe. helpppp

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 02:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM