Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Hey, It works. Almost.
 Post Posted: January 17th, 2018, 11:57 pm 
 

Joined: October 16th, 2016, 5:08 pm
Posts: 20
So, I have been really inconsistently learning c++ over the past two years and I pretty much keep forgetting everything. But I made this program and everything works well, the output is what I want it but . . . The file size is huge!!! like 545KB. I would think it should be somewhere more in the range of 15KB to 40KB. Is there a way that I can make this smaller?

Is it because of the header files I include? I would imagine these would have a lot of unnecessary baggage carried with them for my purposes.

Here's the code and an executable is attached.
Code:
#include <iostream>
#include <windows.h>

using namespace std;

int main()
{
    float x = 0;
    float y = 0;
    float x_buff = 0;
    float y_buff = 0;
    int s;
    float mod;
    float mod_history[16] = {0};
    int res;

    int con = 0;
    int con1;

    cout << " WARNING: Program breaks after 16 different modifiers.";
    cout << "\n \nInput starting value: " ;
    cin >> s;
   
    do{
    cout << "starting value is at " << s << endl << endl;
    cout << endl << "Input Percent Modifier: %" ;
    cin >> mod;
    if(mod == 0){break;}
    cout << endl << "x = y * " << (mod/100) << endl;
    cout << "y = x / " << mod/100 + 1 << endl;

    y = s;
    x = s;

    cout << "How many results to generate?: ";
    cin >> res;

    //Print
    for(int i = 0; i <= (res-1); i++)
    {
        if(x == y){cout << ">> ";};
        cout << x << ", " << y << endl;
        x_buff = x;
        y_buff = y;
        x = y_buff * (mod/100);
        y = x_buff * ((mod/100) + 1);

    };

    cout << "\n \n     To quit, input modifier at 0 \n \n \n";
    cout << "Previous Modifier was at " << mod << "%" << endl << "Modifiers used are: ";

    mod_history[con] = mod;
    con1 = 0;
    do{
                cout << mod_history[con1] << "%";
                con1++;
                if(mod_history[con1]!=0 || con1==16){cout << ", ";}
    }while(mod_history[con1]!=0 || con1==16);
    cout << endl;
    con++;
    }while(x!=0 || con == 16);
    cout << "\n \n \n \nIf we can create stats for this that would be great. \n \n A pattern for how they line up. \n \n Since 50 makes them super small and 90 makes them big, what is the magic number for 2? \n \n what is the magic number for any number? \n \n it is between 61 and 62 and is really close to 61.8 for the number 2. \n" << endl;;
    system("pause");
}


Attachments:
Mathematics.zip [545.16 KiB]
Downloaded 2 times

_________________
You can't be stabbed in the back if you don't have any friends.
Why live? Cause why not.
Top 
 Profile  
Reply with quote  
 Post Posted: January 18th, 2018, 1:03 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3537
Location: Japan
Are you building this in release or debug?

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: January 18th, 2018, 1:12 am 
 

Joined: October 16th, 2016, 5:08 pm
Posts: 20
chili wrote:
Are you building this in release or debug?


Release, Debug is twice as much, but that's understandable.

_________________
You can't be stabbed in the back if you don't have any friends.
Why live? Cause why not.


Top 
 Profile  
Reply with quote  
 Post Posted: January 18th, 2018, 1:15 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3537
Location: Japan
I'm not sure why you include <windows.h>. You don't seem to be calling any of its functions. Usually .h files don't have any impact on your code (unused stuff does not get linked), but there might be some weird stuff that gets included regardless I guess. Try removing windows and see if that makes an impact.

I also have one more change you can make

_________________
Chili


Top 
 Profile  
Reply with quote  
 Post Posted: January 18th, 2018, 3:13 am 
 

Joined: October 16th, 2016, 5:08 pm
Posts: 20
chili wrote:
I'm not sure why you include <windows.h>.


I use system("pause") at the end. I wanted to use it at school and not with the ide's console runner.

I replaced it with cin >> x; and removed windows. it has the same file size.

maybe I am just doing something crucially wrong.

_________________
You can't be stabbed in the back if you don't have any friends.
Why live? Cause why not.


Top 
 Profile  
Reply with quote  
 Post Posted: January 19th, 2018, 1:05 am 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3537
Location: Japan
Well, the main thing you can do is make it link dynamically to the CRT. That should cut down on the size significantly.

But the main thing to understand here is that the size of the exe really isn't a huge issue. In an age where 16 gb main memory capacity is considered the norm, if you're worrying about a few hundred kb something seriously has gone wrong.

_________________
Chili


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 6 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron