Hey, It works. Almost.

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
User avatar
Alacaster
Posts: 81
Joined: October 16th, 2016, 5:08 pm
Location: Spokane, WA

Hey, It works. Almost.

Post by Alacaster » January 17th, 2018, 11:57 pm

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: Select all

#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 99 times
You can't be betrayed if you don't have any friends.
Why live? Cause why not.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Hey, It works. Almost.

Post by chili » January 18th, 2018, 1:03 am

Are you building this in release or debug?
Chili

User avatar
Alacaster
Posts: 81
Joined: October 16th, 2016, 5:08 pm
Location: Spokane, WA

Re: Hey, It works. Almost.

Post by Alacaster » January 18th, 2018, 1:12 am

chili wrote:Are you building this in release or debug?
Release, Debug is twice as much, but that's understandable.
You can't be betrayed if you don't have any friends.
Why live? Cause why not.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Hey, It works. Almost.

Post by chili » January 18th, 2018, 1:15 am

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

User avatar
Alacaster
Posts: 81
Joined: October 16th, 2016, 5:08 pm
Location: Spokane, WA

Re: Hey, It works. Almost.

Post by Alacaster » January 18th, 2018, 3:13 am

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 betrayed if you don't have any friends.
Why live? Cause why not.

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Hey, It works. Almost.

Post by chili » January 19th, 2018, 1:05 am

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

Post Reply