[question] C++ multi application.

[question] C++ multi application.

Post by GoshSpeed on Mon Jun 15, 2009 2:57 pm
([msg=25394]see [question] C++ multi application.[/msg])

Hey,

i building on a project called multiapplication :) .

Question: if x = 2 , and i need the next number : so 2*2 = 4 , 2*4= 8 , 2*8 = 16 etc.
but its a long way to type on my keyboard, is there a faster way to program this?
this is the code that i have done now. :geek:

Code: Select all
#include <iostream>
using namespace std;
int main(void)
#define x 2

{
      cout<< "\n" << x*2;
      cout<<"\n" << x*4;
      cout<<"\n" << x*8;
      cout<<"\n" << x*16;
      cout<<"\n" << x*32;
      cout<<"\n" << x*64;
      cout<<"\n" << x*128;
      cout<<"\n" << x*256;
      cout<<"\n" << x*512;
       cout<<"\n" << x*1024;
       cout<<"\n" << x*2048;
      cout<<"\n" << x*4096;
      cout<<"\n" << x*8192;
      cout<<"\n" << x*16384;
      cout<<"\n" <<x*32768;
      cout<<"\n" <<x*65536;
      cout<<"\n" <<x*131072;
     
      cout <<"\n";
       system ("pause");
       }


Sorry , if my question isn't clear ,i got at the moment not a better explanation :oops: .
And sorry for my language, English is not my native language.


Thanx,

GoshSpeed
GoshSpeed
New User
New User
 
Posts: 3
Joined: Fri May 29, 2009 1:26 pm
Blog: View Blog (0)


Re: [question] C++ multi application.

Post by Tentra on Mon Jun 15, 2009 3:47 pm
([msg=25395]see Re: [question] C++ multi application.[/msg])

Im not sure if this is what you wanted but heres what I did.

Code: Select all
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
   for(int counter = 1; counter <= 17; ++counter)
   {
      cout << pow(2.0, counter) << endl;
   }
}
User avatar
Tentra
Poster
Poster
 
Posts: 161
Joined: Wed Apr 30, 2008 4:52 pm
Blog: View Blog (0)


Re: [question] C++ multi application.

Post by r-ID on Mon Jun 15, 2009 4:14 pm
([msg=25396]see Re: [question] C++ multi application.[/msg])

multiapplication sounds like a pretty damn good program, but the question...
r-ID
Poster
Poster
 
Posts: 172
Joined: Mon Dec 29, 2008 6:04 pm
Blog: View Blog (0)


Re: [question] C++ multi application.

Post by mischief on Mon Jun 15, 2009 6:09 pm
([msg=25397]see Re: [question] C++ multi application.[/msg])

Code: Select all
#include <iostream>
#include <math.h>

int main() {
   for(int counter = 1; counter <= 17; counter <<= 1) {
      std::cout << counter << endl;<br>
   }
}


bitshifting is a faster operation than calling pow ._.
works great for powers of 2 ^^
The whole secret of existence is to have no fear. Never fear what will become of you, depend on no one. Only the moment you reject all help are you freed.
--Buddha
User avatar
mischief
Poster
Poster
 
Posts: 355
Joined: Wed Jan 07, 2009 4:16 pm
Blog: View Blog (0)


Re: [question] C++ multi application.

Post by xcurious on Tue Jun 16, 2009 1:01 pm
([msg=25437]see Re: [question] C++ multi application.[/msg])

GoshSpeed, I recommend you learn about looping in C++ or loops in general.

Here's a link to get you started http://www.cprogramming.com/tutorial/lesson3.html
- Apologies to all who I have flamed in the past. Thanks mods for unbanning me.


ckw100 wrote:so i have been pacticeing my batch file hacking for networks
xcurious
Experienced User
Experienced User
 
Posts: 79
Joined: Sun Sep 21, 2008 3:49 pm
Blog: View Blog (0)


Re: [question] C++ multi application.

Post by GoshSpeed on Tue Jun 16, 2009 1:31 pm
([msg=25438]see Re: [question] C++ multi application.[/msg])

xcurious wrote:GoshSpeed, I recommend you learn about looping in C++ or loops in general.

Here's a link to get you started http://www.cprogramming.com/tutorial/lesson3.html


Hey,

thanx .

And every one who had post something.. ( uuh: Tentra , your code works , thanx about that.)


multiapplication sounds like a pretty damn good program, but the question...

Yeah sorry r-ID, i got non other name for it :roll: .

Thanx to all,

GoshSpeed
GoshSpeed
New User
New User
 
Posts: 3
Joined: Fri May 29, 2009 1:26 pm
Blog: View Blog (0)



Return to C and C++

Who is online

Users browsing this forum: No registered users and 0 guests