Jump to content

How's It Looking?


Kamikaze_Badger

Recommended Posts

Ok, almost done with the OS Stresser(I'll be porting it over to Assembly for burning the CPU). Anyone mind telling me what I need to improve upon, other than the loops?

 

 

/* Here's our main part of the program. Functions, etc, are in here...
** This is all under the GNU GPL. You may modify it in any way that pleases you
** It works by stressing out the OS right now. I'll get to porting it over
** to Assembly after I get more fluent in C++. */

#include <iostream.h>
#include "Defs.h"

using namespace std;

double dblTrillion = "1000000000000";

int main();
{
    cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl; <<
    "continue, or \"exit\" to quit: " << endl; <<;
    
    cin >> INTRO_ANSWER;
    
    if (INTRO_ANSWER == INTRO_COMPARE)
     {
         //Going to use pseudo code for now, as my net is down due to worms,
         //and I can't remember the proper usage of do-while loops
         
         do 
            ( int z;
             z = lnTrillFunc ( .0000000000000000002 , .0000000000000000002 );
             cout << "We're at: " << z << " right now."; )
             
         while ( z != dblTrillion )
     }
     
     else
     
         {
             cout << "Goodbye!";
             
                 return(0);
         }
     }
         

   
    double dblTrillFunc ( double dblDeciOne , double dblDeciTwo );
  
  {
      long lnTrillResult;
      
      /* double dblDeciOne(.000000000000000000002);
      double dblDeciTwo(.000000000000000000002); */
      
      lnTrillResult = ( dblDeciOne * dblDeciTwo );
      
      return(lnTrillResult);
  }
  
  
  
  
  /* Credits:
      
     Emily, for being an everlasting pillar of support and love. *hug*
     AntiOnline members, for helping me out with all of this project.
     Bjorne Stoustruppe, for making this programming language. =)
     Everyone at the OCC, for being my friends and helping me out with life issues
     Mike McGrath, for writing C++ in Easy Steps, the best C++ book EVAR!
     Dad, for your support in my modding and programming.
     Everyone at Bloodshed, for making Dev-C++, the best open source C/++ IDE.
     Anyone else I missed, thanks anyhow! You've all made this program possible. */

 

 

Defs.h:

 

#define INTRO_ANSWER
#define INTRO_COMPARE "exit"

Share this post


Link to post
Share on other sites

first looks... it won't compile.

 

1)

cin >> INTRO_ANSWER;

 

INTRO_ANSWER should be a variable and not a preprocessor macro.

 

2)

"100000000" or whatever it is shouldn't be enclosed in "'s, since that indicates a string, or array of characters. It's likely too big of a number anyhow..

 

3)

main(); shouldn't have the ; at the end

 

4)

endl; shouldn't have ; at the end either

 

5) the pseudo-code isn't really pseudo code at all :D

 

do {

 

} while (condition); the { are ( and ) in your code.

 

6)

<< endl; <<;

 

no need for that << at the end

 

7)

int z; should be moved outside the loop I think.

 

8)

long lnTrillResult should be a double by the looks of things

 

9)

some nice indenting wouldn't go a miss

 

10)

Defs.h should include the function prototype for dblTrillFunc or whatever it is :) Won't stop it compiling, however... you seem to have changed the name along the lines as you're calling it lnTrillFunc in the loop.

 

11)

int z shouldn't even be an int, it should be a double.. since that's what your function returns

 

INTRO_ANSWER == INTRO_COMPARE should be != INTRO_COMPARE probly too..

 

EDIT: Oh yeah and it shouldn't actually be INTRO_ANSWER == INTRO_COMPARE or whatever at all, because that would be comparing pointers, which are unlikely to ever be the same unless you're special :) you'll have to use something like strcmp.. there's probably other better functions I don't know about though.

 

UPDATE: Had a quick go in C. Hows this?

 

#include <stdio.h>
#include <assert.h>
#include <string.h>

#define INPUTBUFFER 5

double MultiplyDoubles(double, double);

int main(void) {
       char *input;
       double z = 0, dblTrill = 100000;

       input = (char *)malloc(sizeof(char) * INPUTBUFFER);
       assert(input != NULL);
       memset(input, 0, INPUTBUFFER);

       printf("Welcome to the Burn-A-Natar 3000!\n");
       printf("Type in anything to continue, or \"exit\" to quit\n");
       printf("> ");

       fgets(input, INPUTBUFFER, stdin);
       if (strcmp(input, "exit") == 0) {
               printf("Exit\n");
       } else {
               while (z < dblTrill) {
                       z = z + MultiplyDoubles(0.00002, 0.00002);
                       printf("z is currently at: %f\n", z);
               }
       }

       return 0;
}

double MultiplyDoubles(double dblOne, double dblTwo) {
       return (dblOne * dblTwo);
}

 

The strcmp is a little rough, "exit" and whatever was in input wouldn't compare correctly if the input buffer was bigger than 4 character + \0 (5). Other than that it seems to run: (increased from 0.00002 to 0.002 for example)

 

(mrboo|bone)/home/mrboo$ ./mburn

Welcome to the Burn-A-Natar 3000!

Type in anything to continue, or "exit" to quit

>

z is currently at: 0.000004

z is currently at: 0.000008

z is currently at: 0.000012

z is currently at: 0.000016

z is currently at: 0.000020

z is currently at: 0.000024

z is currently at: 0.000028

z is currently at: 0.000032

z is currently at: 0.000036

z is currently at: 0.000040

z is currently at: 0.000044

z is currently at: 0.000048

z is currently at: 0.000052

z is currently at: 0.000056

z is currently at: 0.000060

z is currently at: 0.000064

z is currently at: 0.000068

z is currently at: 0.000072

z is currently at: 0.000076

z is currently at: 0.000080

z is currently at: 0.000084

z is currently at: 0.000088

z is currently at: 0.000092

z is currently at: 0.000096

z is currently at: 0.000100

 

*cough* I know nothing of threads for Windows - or in general really - so I won't post the code unless someone really wants to see. I just made it print z's current value from z once every second, so that the majority of the CPU time doesn't end up in printf (alot quicker on a poor 133). Back at 0.00002 * 0.00002:

 

(mrboo|bone)/home/mrboo$ ./mburn

Welcome to the Burn-A-Natar 3000!

Type in anything to continue, or "exit" to quit

>

INFO: Currently at: 0.0000200308

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0008933108

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0017689056

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0026552932

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0035014040

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0043718140

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0052760348

INFO: --- Sleeping for 1 second ---

INFO: Currently at: 0.0061525420

 

Chunky monkeys or what? Sorry for the long post.

Share this post


Link to post
Share on other sites

Ok, getting to work on it.

 

 

 

 

 

Man, programming is tough :(.

 

 

EDIT: How do you do the pauses? I've always wanted to know...

 

 

 

 

Anyway, I did some work on it, going by what you said, and it's giving me 5 errors.

 

19 D:\Dev-Cpp\stress-main.cpp syntax error before `int'

 

24 D:\Dev-Cpp\stress-main.cpp syntax error before `>>' token

 

31 D:\Dev-Cpp\stress-main.cpp syntax error before `<<' token

 

56 D:\Dev-Cpp\stress-main.cpp [Warning] initialization to `long int' from ` double'

 

56 D:\Dev-Cpp\stress-main.cpp [Warning] argument to `long int' from `double'.

 

 

Here's the updated code:

 

/* Here's our main part of the program. Functions, etc, are in here...
** This is all under the GNU GPL. You may modify it in any way that pleases you
** It works by stressing out the OS right now. I'll get to porting it over
** to Assembly after I get more fluent in C++. */

#include <iostream>
#include <string>

using namespace std;

string intro_answer;

string intro_compare = "exit";

long lnBillion = 1000000000;

double z

int main()
{
    cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl <<
    "continue, or \"exit\" to quit: " << endl;
    
    cin >> intro_answer;
    
    if (intro_answer == intro_compare)
     {   
         do 
            {
             z = lnTrillFunc ( .0000000000000000002 , .0000000000000000002 );
             cout << "We're at: " << z << " right now.\n";
            }    
             
         while ( z < lnBillion )
     }
     
     else
     
         {
             cout >> "Goodbye!";
             
                 return(0);
         }
     }
         

   
    double dblTrillFunc ( double dblDeciOne , double dblDeciTwo )
  
  {
      //long lnTrillResult;
      
      /* double dblDeciOne(.000000000000000000002);
      double dblDeciTwo(.000000000000000000002); */
      
      long lnTrillResult = ( dblDeciOne * dblDeciTwo );
      
      return(lnTrillResult);
  }

Share this post


Link to post
Share on other sites

Do you not have a compiler to test with or summit?

 

Yes :) You're only, what.. 14? I was still playing with Delphi at 14. I didn't really bother touching C till we got taught a little at Uni this year, even though I wanted to learn it before hand (probably since I was about 14 actually).

 

It's not so hard once you learn the basics. The Uni lectures really cleared up the whole pointer mystery for me. I feel ... enlightened. Perhaps reading a good C programming book will help?

 

It gets hard when you start looking at real programs written by other people :)

 

EDIT:

 

1) double z has no semi-colon.

2) cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl <<

"continue, or \"exit\" to quit: " << endl;

 

multi-lines you'll want to use a... \\ at the end of the line I think it is.. I think

 

cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl << \\

"continue, or \"exit\" to quit: " << endl;

 

3 & 4) you're still trying to put the result of a floating point operation (double * double) into a long without a cast.

 

long lnTrillResult = ( dblDeciOne * dblDeciTwo );

 

change to double lnTrillResult.

 

Also, you don't want to be pausing for a second without going and doing the printing in a thread really, since you're also going to be pausing the actual calculation otherwise :P If you want to do it in a single threaded program I guess you could do it by .. using an if() together with some funky get current time function and doing some working out from when you last printed out z.

Share this post


Link to post
Share on other sites

Lol, yea, I've being wanting to get into C++ ever since I met pRiNcE kAhUnA last year on TFC. He was a dumbarse, but he got me wanting to learn C++. I've found that using the online tutorials instead of buying books really helps when it comes to learning programming languages, and they're usually more up-to-date.

 

 

Btw, a pointer is a variable that stores the memory cell address that a char or integer is in, right?

 

 

Btw, I'm using the MingW or whatever compiler that came with Dev-C++.

 

 

 

And... it's not a bad thing that I almost crapped my pants when I read the Wolfenstein: ET source code, is it?

 

 

EDIT: Ok, with the \\ thing, it told me I had a stray one. I also fixed up my function call(had the prefix wrong), and it's now saying that "dblTrillFunc" is undeclared.

 

 

Current code:

 

/* Here's our main part of the program. Functions, etc, are in here...
** This is all under the GNU GPL. You may modify it in any way that pleases you
** It works by stressing out the OS right now. I'll get to porting it over
** to Assembly after I get more fluent in C++. */

#include <iostream>
#include <string>

using namespace std;

string intro_answer;

string intro_compare = "exit";

long lnBillion = 1000000000;

double z;

int main()
{
    cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl << \
"continue, or \"exit\" to quit: " << endl;
    
    cin >> intro_answer;
    
    if (intro_answer == intro_compare)
     {   
         do 
            {
             z = dblTrillFunc ( .0000000000000000002 , .0000000000000000002 );
             cout << "We're at: " << z << " right now.\n";
            }    
             
         while ( z < lnBillion )
     }
     
     else
     
         {
             cout >> "Goodbye!";
             
                 return(0);
         }
     }
         

   
    double dblTrillFunc ( double dblDeciOne , double dblDeciTwo )
  
  {
      //long lnTrillResult;
      
      /* double dblDeciOne(.000000000000000000002);
      double dblDeciTwo(.000000000000000000002); */
      
      double lnTrillResult = ( dblDeciOne * dblDeciTwo );
      
      return(lnTrillResult);
  }
  
  
  
  
  /* Credits:
      
     Emily, for being an everlasting pillar of support and love. *hug*
     AntiOnline members, for helping me out with all of this project.
     Bjorne Stoustruppe, for making this programming language. =)
     Everyone at the OCC, for being my friends and helping me out with life issues
     Mike McGrath, for writing C++ in Easy Steps, the best C++ book EVAR!
     Dad, for your support in my modding and programming.
     Everyone at Bloodshed, for making Dev-C++, the best open source C/++ IDE.
     Anyone else I missed, thanks anyhow! You've all made this program possible. */

Share this post


Link to post
Share on other sites

It's not bad that you crapped yourself, no :)

 

A pointer is a variable that holds an address, it could be to an integer, char, double, struct, function... whatever. Now think pointers to pointers :) It's a bit of a mind . when you start going there. Would you like an example?

 

Sorry, I've been using Matlab most of the day for a crappy assignment and the multiline in that is '...', looks like you have that sussed though.

 

It says it's undeclared, because it is. You need a function prototype to use that function from any location. If not then move the function above main. You wouldn't say

 

z = 10;

int z;

 

now, would you? :P

 

Function prototype for it would look like:

 

double name(double, double);

Share this post


Link to post
Share on other sites

Ok, put the function right under the "using namespace std;" part. Now, I'm getting the following errors:

 

D:\Dev-Cpp\stress-main.cpp In function `int main()':

 

51 D:\Dev-Cpp\stress-main.cpp syntax error before `}' token

 

56 D:\Dev-Cpp\stress-main.cpp no match for 'operator>>' in 'std::cout >> "Goodbye!"'

 

 

The second error is the } i'm using to close off the if block, to save you some time.

Share this post


Link to post
Share on other sites

second error the >> should be <<

 

cout >> "Goodbye!"; should read cout << "bye";

 

and as a guess, without seeing the code... the

 

do {

 

} while() isn't terminated with a ; so stick a ; on the end.

 

If you want to see a single threaded pause type thing using the current time (not sure if it'll work with Windows mind). Here's a rather bad example:

 

#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>

#define INPUTBUFFER 5

double MultiplyDoubles(double, double);

int main(void) {
       char *input;
       double z = 0, dblTrill = 100000;
       int pid;
       struct timespec ts;
       time_t prevTime;

       input = (char *)malloc(sizeof(char) * INPUTBUFFER);
       assert(input != NULL);
       memset(input, 0, INPUTBUFFER);

       printf("Welcome to the Burn-A-Natar 3000!\n");
       printf("Type in anything to continue, or \"exit\" to quit\n");
       printf("> ");

       fgets(input, INPUTBUFFER, stdin);
       if (strcmp(input, "exit") == 0) {
               printf("Exit\n");
       } else {
               prevTime = 0;
               while (z < dblTrill) {
                       z = z + MultiplyDoubles(0.00002, 0.00002);

                       clock_gettime(CLOCK_REALTIME, &ts);
                       if (prevTime < ts.tv_sec) {
                               prevTime = ts.tv_sec;
                               printf("INFO: Currently at: %-10.10f\n", z);
                       }
               }
       }

       return 0;
}

double MultiplyDoubles(double dblOne, double dblTwo) {
       return (dblOne * dblTwo);
}

 

Seems to print out about once every second ish anyhow.

Share this post


Link to post
Share on other sites

Markie...

 

 

 

You're a miracle worker! IT COMPILED!

 

 

*kisses markie in a friendly manner*

 

 

 

Updated code, courtesy of markie's help:

 

/* Here's our main part of the program. Functions, etc, are in here...
** This is all under the GNU GPL. You may modify it in any way that pleases you
** It works by stressing out the OS right now. I'll get to porting it over
** to Assembly after I get more fluent in C++. */

#include <iostream>
#include <string>

using namespace std;



double dblTrillFunc ( double dblDeciOne , double dblDeciTwo )
  
  {
      //long lnTrillResult;
      
      /* double dblDeciOne(.000000000000000000002);
      double dblDeciTwo(.000000000000000000002); */
      
      double lnTrillResult = ( dblDeciOne * dblDeciTwo );
      
      return(lnTrillResult);
  }


string intro_answer;

string intro_compare = "exit";

long lnBillion = 1000000000;

double z;

int main()
{
    cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl << \
"continue, or \"exit\" to quit: " << endl;
    
    cin >> intro_answer;
    
    if (intro_answer == intro_compare)
     {   
         do 
            {
             z = dblTrillFunc ( .0000000000000000002 , .0000000000000000002 );
             cout << "We're at: " << z << " right now.\n";
            }    
             
         while ( z < lnBillion );
     }
     
     else
     
         {
             cout << "Bye";
             
                 return(0);
         }
     }
         

   
    
  
  
  
  
  /* Credits:
      
     Emily, for being an everlasting pillar of support and love. *hug*
     AntiOnline members, for helping me out with all of this project.
     Bjorne Stoustruppe, for making this programming language. =)
     Everyone at the OCC, for being my friends and helping me out with life issues
     Mike McGrath, for writing C++ in Easy Steps, the best C++ book EVAR!
     Dad, for your support in my modding and programming.
     Everyone at Bloodshed, for making Dev-C++, the best open source C/++ IDE.
     Anyone else I missed, thanks anyhow! You've all made this program possible.
     Markiemrboo, from the OCC, for helping me with all the bugs and stuff. YOU GET A COOKIE! */

 

 

EDIT: Got a problem... says "We're at 4e-038" right now when I type in "exit"...

Share this post


Link to post
Share on other sites

*bows* .. *hair goes in eyes* .. *runs around screaming* .. *falls off stage*

 

Thank you!

 

rar rar rar.. you could stick that function back at the bottom though and use a prototype :) a little tidier.

 

/* Here's our main part of the program. Functions, etc, are in here...
** This is all under the GNU GPL. You may modify it in any way that pleases you
** It works by stressing out the OS right now. I'll get to porting it over
** to Assembly after I get more fluent in C++. */

#include <iostream>
#include <string>

using namespace std;

double dblTrillFunc(double, double);

string intro_answer;
string intro_compare = "exit";
long lnBillion = 1000000000;
double z;

int main()
{
   cout << "Welcome to the Burn-A-Natar 3000! Type in anything to" << endl << \
"continue, or \"exit\" to quit: " << endl;
  
   cin >> intro_answer;
  
   if (intro_answer == intro_compare)
    {  
        do
           {
            z = dblTrillFunc ( .0000000000000000002 , .0000000000000000002 );
            cout << "We're at: " << z << " right now.\n";
           }    
            
        while ( z < lnBillion );
    }
    
    else
    
        {
            cout << "Bye";
            
                return(0);
        }
    }
        

double dblTrillFunc ( double dblDeciOne , double dblDeciTwo )

 {
     //long lnTrillResult;
    
     /* double dblDeciOne(.000000000000000000002);
     double dblDeciTwo(.000000000000000000002); */
    
     double lnTrillResult = ( dblDeciOne * dblDeciTwo );
    
     return(lnTrillResult);
 }

 
 /* Credits:
    
    Emily, for being an everlasting pillar of support and love. *hug*
    AntiOnline members, for helping me out with all of this project.
    Bjorne Stoustruppe, for making this programming language. =)
    Everyone at the OCC, for being my friends and helping me out with life issues
    Mike McGrath, for writing C++ in Easy Steps, the best C++ book EVAR!
    Dad, for your support in my modding and programming.
    Everyone at Bloodshed, for making Dev-C++, the best open source C/++ IDE.
    Anyone else I missed, thanks anyhow! You've all made this program possible.
    Markiemrboo, from the OCC, for helping me with all the bugs and stuff. YOU GET A COOKIE! */

 

EDIT: Yes, see my comment about strcmp earlier :) I don't know how this 'string' thing works that you're using. I can only imagine it's some sort of friendly wrapper around character arrays, is it? Uh... you could try === instead, that might be a Java only thing though?

Share this post


Link to post
Share on other sites

Whatcha think a string is when it's stored in memory? :) It's an array of characters terminated by a \0. Chances are that string in C++ is just a friendlier way of using char's to try and get away from using char pointers and malloc.

 

Since C++ is an OO language, you may be able to do something like in Java... say... stringVariable.CompareTo("some text");

 

EDIT: Here's a time thing that'll work with Windows.. and I remembered to free my malloc'd data this time too, not that it matters much for like 5 bytes :rolleyes:

 

#include <stdio.h>
#include <assert.h>
#include <malloc.h>
#include <string.h>

#ifdef _WIN32
#include <time.h>
#else
#include <sys/time.h>
#endif

#define INPUTBUFFER 5

double MultiplyDoubles(double, double);

int main(void) {
       char *input;
       double z = 0, dblTrill = 100000;
       time_t curTime;
       time_t prevTime;

       input = (char *)malloc(sizeof(char) * INPUTBUFFER);
       assert(input != NULL);
       memset(input, 0, INPUTBUFFER);

       printf("Welcome to the Burn-A-Natar 3000!\n");
       printf("Type in anything to continue, or \"exit\" to quit\n");
       printf("> ");

       fgets(input, INPUTBUFFER, stdin);
       if (strcmp(input, "exit") == 0) {
               printf("Exit\n");
       } else {
               prevTime = time(NULL);
               while (z < dblTrill) {
                       z = z + MultiplyDoubles(0.00002, 0.00002);

                       curTime = time(NULL);
                       if ((curTime - prevTime) >= 1) {
                               prevTime = curTime;
                               printf("INFO: Currently at: %-10.10f\n", z);
                       }
               }
       }

free(input);
       return 0;
}

double MultiplyDoubles(double dblOne, double dblTwo) {
       return (dblOne * dblTwo);
}

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...