Thread: You title it.

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246

    You title it.

    What this program does is obvious. But there is a small problem: we don't need all the pairs (ex. 800x1200) and we could use less memory if we had made xy={800*600, 1024*768...}. But we want the program to print the values in a loop. Any idea to solve this problem?
    Code:
    int main()
    {   
    	unsigned short x[] = {800, 1024, 1152,1600,2048};
    	unsigned short y[] = {600, 768, 864 ,1200, 1536};
    	unsigned short c[] = {2,4};
    	for(int cn=0; cn<2;cn++)
    		for(int i=0; i<5; i++)
    			cout<<x[i]<<"x"<<y[i]<<"x"<<c[cn]*8<<" = "<<(x[i]*y[i]*c[cn])/(1024*1024.0f)<<" MB(s)"<<endl;
    
    	return 0;
    }
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    312
    how about a struct?
    Code:
    struct foo
    {
        short x;
        short y;
    }
    
    foo bar;
    bar.x=800;
    bar.y=600;

  3. #3
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    how about a struct?
    That wouldn't help??

    What help is this.

    y = x*6/8

    the x's can all be divided by 32 if you really wanted to save space too

  4. #4
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,246
    So I change a code a little
    Code:
    int main()
    {   
    	unsigned short x[] = {800, 1024, 1152, 1600, 1920, 1920, 2048};
    	unsigned short y[] = {600, 768, 864, 1200, 1080, 1200, 1536};
    	unsigned short c[] = {2,4};
    	for(short cn=0; cn<2;cn++)
    		for(short i=0; i<7; i++)
    			cout<<x[i]<<"x"<<y[i]<<"x"<<c[cn]*8<<" = "<<(x[i]*y[i]*c[cn])/(1024*1024.0f)<<" MB"<<endl;
    
    	return 0;
    }
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extract Title from plain text file
    By Todd88 in forum C++ Programming
    Replies: 10
    Last Post: 11-21-2008, 09:47 AM
  2. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  3. Title and Icon On Window
    By matth in forum C++ Programming
    Replies: 0
    Last Post: 03-21-2005, 03:53 PM
  4. Change Title in a MFC SDI
    By hick.hack in forum Windows Programming
    Replies: 1
    Last Post: 12-15-2003, 04:15 PM
  5. Child window with active (highlighted) title bar: Possible?
    By JasonD in forum Windows Programming
    Replies: 7
    Last Post: 10-16-2003, 06:43 AM