Jump to content

First C++ Program..

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
10 replies to this topic

#1
mindsurfer

mindsurfer

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
hi guys .... i am new to programming and this is my first C++ program... the only problem i have is that the size is large...almost 5MB... is there anything that can help me to reduce the size?

here is my source...

#include <iostream>



int main()


{


float number1,number2;


float sum,subtract,product,division;


std::cout <<"Enter the value of number1 :";

std::cin >>number1;

std::cout <<"Enter the value of number2 :";

std::cin >>number2;


sum=number1+number2;

subtract=number1-number2;

product=number1*number2;

division=number1/number2;


std::cout <<"sum is :"<<sum <<std::endl;

std::cout <<"subtract is :"<<subtract <<std::endl;

std::cout <<"product is :"<<product <<std::endl;

std::cout <<"division is :"<<division <<std::endl;


return 0;


}

any help will be appreciated :)
MindSurfer

#2
bluekads

bluekads

    Newbie

  • Members
  • Pip
  • 2 posts
good work
FYI:
instead of using std:: several times
use

using namespace std;


the code will be

#include <iostream>


using namespace std;


int main()


{


float number1,number2;


float sum,subtract,product,division;


cout <<"Enter the value of number1 :";

cin >>number1;

cout <<"Enter the value of number2 :";

cin >>number2;


sum=number1+number2;

subtract=number1-number2;

product=number1*number2;

division=number1/number2;


cout <<"sum is :"<<sum <<std::endl;

cout <<"subtract is :"<<subtract <<std::endl;

cout <<"product is :"<<product <<std::endl;

cout <<"division is :"<<division <<std::endl;


return 0;


}


#3
mindsurfer

mindsurfer

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
Thanks ... but i want to know how can i reduce the size from 5MB to something smaller?
MindSurfer

#4
bluekads

bluekads

    Newbie

  • Members
  • Pip
  • 2 posts
unfortunatly, i don't know...

but if you want to send your program to email or upload it to the web, just send the .cpp file
and if you can see that the largest size of the program is in the debug folder only...

#5
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
How are you compiling your source code? 5 mb for that small a script is completely outrageous. You only have 1 declaration (#include), completely ludacris. Maybe using an IDE would reduce the size (almost definately). If you're using Windows and developing just for Windows, you can use MS's Visual Studio which will make .exe's that run off of the .NET Framework (all libraries already on the target machine = very small exe). Also, I would suggest Bloodshed's Dev-Cpp.

#6
kkelly

kkelly

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
Wowwee, that is gi-normous. :eek: Which compiler are you using?

#7
mindsurfer

mindsurfer

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
i am using MSVC++ 6.0... the size of the executable is 512Kb and the size of the whole "Debug" folder is 5MB... is it that i have to turn off Debug options in MSVC++ ?
thanks
MindSurfer

#8
v0id

v0id

    Retired

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,936 posts
I'm not experienced with MSVC++, but try turn it off. Or maybe you should choose another compiler. I can get it down on 260KB, using "g++" and "strip," both from GCC.

#9
kkelly

kkelly

    Learning Programmer

  • Members
  • PipPipPip
  • 49 posts
I haven't used that version, but I am thinking you can change the build setting to "release" and trim out the overhead that comes with debugging. I haven't used that version of MSVC++, but according to some documentation, you would go to Build >> Set Active Configuration and select "Release".
Once you compile the executable, I think it will show up in a folder called "Release" in the same directory as the "Debug" folder.

#10
mindsurfer

mindsurfer

    Learning Programmer

  • Members
  • PipPipPip
  • 39 posts
thanks for the help guys... i installed code blocks and it optimizes the size of the program itself.. but i will still try to do a bit of research on MSVC++ 6.0..
MindSurfer

#11
Victor

Victor

    Programmer

  • Members
  • PipPipPipPip
  • 116 posts
Sorry, I accidentally posted what was already said (didn't read sorry lol), and I didn't figure out how to delete post.