Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 08-08-2007, 07:49 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2007
Posts: 10
Default C++:Adding two numbers

We have just started C++ in college

Code:
#include <iostream>
using namespace std;
main()
{ int a,b,c;
  cout<<"Enter two nos.:";
  cin>> a >> b;
  c=a+b;
  cin.get();
  cout<<"Sum is"<<c<<"";
  cin.get();
  
}
but on compiling and running it{no errors here}nothing happens when i enter two nos. and press enter.Why is it so??can someone guide me??
spinach-guy is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 08-08-2007, 08:24 PM   #2 (permalink)
IM AS MAD AS HELL!!
 
max_demon's Avatar
 
Join Date: Oct 2006
Location: localhost
Posts: 1,596
Default Re: C++:Adding two numbers

^^^Me too .
Help me
__________________
When someone dies in the grip of a powerful rage... a curse is born.

Kayako Saeki: Croakkkkkkkkkkkkkkkkkkkkk!
max_demon is offline  
Old 08-08-2007, 08:40 PM   #3 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default Re: C++:Adding two numbers

May I know which compiler are you using.

This program will run properly
Quote:
#include<iostream.h>
main ()
{
int a,b,c;
cout<<"Enter two nos:: " ;
cin>>a>>b;
c=a+b;
cout<<"Sum is :: "<<c ;
}
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
Old 08-08-2007, 10:16 PM   #4 (permalink)
Wise Old Crow
 
blueshift's Avatar
 
Join Date: Apr 2005
Location: Inside the Pixel
Posts: 1,227
Default Re: C++:Adding two numbers

Is there any need to use instances of cin.get() ?
See in the Output window of the compiler. u might see the result/ o/p their.
Try using getch(); function instead at the end.

Try using getch(); function in the end instead.
__________________
http://twitter.com/blueshift155

Last edited by blueshift; 08-08-2007 at 10:16 PM. Reason: Automerged Doublepost
blueshift is offline  
Old 08-08-2007, 11:16 PM   #5 (permalink)
In The Zone
 
Join Date: May 2007
Location: Pune
Posts: 247
Default Re: C++:Adding two numbers

Quote:
Originally Posted by spinach-guy
We have just started C++ in college

Code:
#include <iostream>
using namespace std;
main()
{ int a,b,c;
  cout<<"Enter two nos.:";
  cin>> a >> b;
  c=a+b;
  cin.get();
  cout<<"Sum is"<<c<<"";
  cin.get();
  
}
but on compiling and running it{no errors here}nothing happens when i enter two nos. and press enter.Why is it so??can someone guide me??
No need to use cin.get(). That too for 2 times!!!
When supplying input add a space between the numbers.
Even current program runs fine in MSVC6.
Which compiler you are using?
Also if using Tubro C++ 3 or similar DOS based compiler, then remember they are really old. Instead try using free Microsoft VC++ Express Edition which is based on current standard.
__________________
Anyone who has never made a mistake has never tried anything new
sandeepk is offline  
Old 08-08-2007, 11:51 PM   #6 (permalink)
IM AS MAD AS HELL!!
 
max_demon's Avatar
 
Join Date: Oct 2006
Location: localhost
Posts: 1,596
Default Re: C++:Adding two numbers

Dev C++?
__________________
When someone dies in the grip of a powerful rage... a curse is born.

Kayako Saeki: Croakkkkkkkkkkkkkkkkkkkkk!
max_demon is offline  
Old 08-08-2007, 11:52 PM   #7 (permalink)
NP : Crysis
 
xbonez's Avatar
 
Join Date: Mar 2007
Location: City 17
Posts: 1,415
Default Re: C++:Adding two numbers

leave out all the complications. just run

Quote:
#include<iostream.h>
#include<conio.h>
{
clrscr();
int a,b;
cin>>a>>b;
cout<<a+b;
getch();
}
simple as tht
__________________
Gaming: Phenom II x4 965BE @ 3.6Ghz/Corsair H50 Liquid Cooling/MSI 790FX-GD70/2x2GB GSkill Ripjaws 7-7-7-24/3 x GTX 470 w/Zalman VF3000F/Corsair 850W PSU/Antec 1200/2xSpinpoint F3 500Gb RAID 0
xbonez is offline  
Old 09-08-2007, 09:29 AM   #8 (permalink)
In The Zone
 
whoopy_whale's Avatar
 
Join Date: Sep 2004
Location: Bermuda Triangle
Posts: 239
Default Re: C++:Adding two numbers

Don.t forget to add the main() function too...

Code:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a,b;
cin>>a>>b;
cout<<a+b;
getch();
}
__________________
In just two days, tomorrow will be yesterday.
whoopy_whale is offline  
Old 09-08-2007, 10:21 AM   #9 (permalink)
I am Optimus Prime
 
navjotjsingh's Avatar
 
Join Date: Feb 2005
Location: Delhi, India
Posts: 1,919
Default Re: C++:Adding two numbers

And what's with your second line: using namespace std;

It also of no use.
navjotjsingh is offline  
Old 09-08-2007, 10:40 AM   #10 (permalink)
Wise Old Owl
 
piyush gupta's Avatar
 
Join Date: Sep 2005
Location: never land
Posts: 1,284
Default Re: C++:Adding two numbers

^^thats staandard namespace u use for ur program not useful here but itzz very useful in big projects with 1000s of code
piyush gupta is offline  
Old 09-08-2007, 01:22 PM   #11 (permalink)
Right Off the Assembly Line
 
Join Date: Jul 2007
Posts: 10
Default Re: C++:Adding two numbers

I am using bloodshed Cev C++ which i got from a Digit CD
Quote:
And what's with your second line: using namespace std;

It also of no use.
Without using this,i get error like cin,cout not defined...something like that

Quote:
No need to use cin.get(). That too for 2 times!!!
What's the exact use of this function.has it got something to do with user needing to press enter to continue??also what's the use of cin.ignore()??
spinach-guy is offline  
Old 09-08-2007, 05:50 PM   #12 (permalink)
Alpha Geek
 
g_goyal2000's Avatar
 
Join Date: Jul 2004
Location: New Delhi
Posts: 617
Default Re: C++:Adding two numbers

Why not simply use Turbo C++???
It's much better & easy to use for starters.

Here's the link to Turbo C++
http://rapidshare.com/files/47910015/TURBOC.EXE

Download it, open the file using Winzip or Winrar and extract it to C: drive.

Be sure to check that the option to use path names is checked otherwise the files will overwrite themselves & u'll have a corrupt complier in your hands.

Do Not execute the file directly by double clicking on it.
__________________
Dell Studio 1558, Intel i5 M430 @ 2.27 Ghz, 4 GB RAM, 1 GB ATI 5470 Mobility, 500 GB HDD, IDT HD Audio with Creative X-Fi MB software

Last edited by g_goyal2000; 10-08-2007 at 12:30 AM. Reason: Automerged Doublepost
g_goyal2000 is offline  
Old 09-08-2007, 06:10 PM   #13 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default Re: C++:Adding two numbers

Dint want to start a new thread as problem with the compiler in question.

When I run a Hello world program in C using Dev-CPP, I get the following error.

Quote:
Compiler: Default compiler
Executing gcc.exe...
gcc.exe "C:\Users\Casanova\Documents\HelloWorld.c" -o "C:\Users\Casanova\Documents\HelloWorld.exe" -I"F:\Apps\Dev-Cpp\include" -L"F:\Apps\Dev-Cpp\lib"
gcc.exe: installation problem, cannot exec `cc1': No such file or directory

Execution terminated
Compilation successful
What to do?
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
Old 09-08-2007, 10:41 PM   #14 (permalink)
In The Zone
 
Join Date: May 2007
Location: Pune
Posts: 247
Default Re: C++:Adding two numbers

Quote:
Originally Posted by spinach-guy
I am using bloodshed Cev C++ which i got from a Digit CD
First of all it is good that you are using Dev C++ which is a good C++ compiler.
Quote:
using namespace std;
Without using this,i get error like cin,cout not defined...something like that
It is needed. Read more about namespace. It is a new concept introduced in ISO C++. It is needed in most of the new version compilers.


Quote:
No need to use cin.get(). That too for 2 times!!!
Quote:
Originally Posted by spinach-guy
What's the exact use of this function.has it got something to do with user needing to press enter to continue??also what's the use of cin.ignore()??
This is not needed. It was a function used to get a single character from input stream. It is just a way to get character from keyboard like getch() or getche() used in C. For your program it is not needed at all. Read more about 'cin' from whichever book you are using. I would suggest Balaguruswamy as a good book to beginners. There are others also but this does provide a better explaination about all the things related to STL for the beginners.
__________________
Anyone who has never made a mistake has never tried anything new
sandeepk is offline  
Old 10-08-2007, 04:08 PM   #15 (permalink)
Ron
||uLtiMaTE WinNER||
 
Ron's Avatar
 
Join Date: Nov 2006
Location: Kathmandu,Nepal
Posts: 698
Arrow Re: C++:Adding two numbers

Hey
I hv also just started C++........May be thsi will help u......

Code:
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b;
cin>>a>>b;
cout<<a+b;
getch();
}
or

Code:
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
int a,b;
cout<<"input 1st no";
cin>>a;
cout<<"input 2nd no";
cin>>b;
cout<<a+b;
getch();
}
__________________
||uLtiMaTE WinNER||
Ron is offline  
Old 10-08-2007, 04:13 PM   #16 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,905
Default Re: C++:Adding two numbers

Let me post a good ANSI C++ Program ...

Code:
# include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    cout << "Enter two numbers : ";
     cin >> a >> b;
    
    c = a + b;
    
    cout << "Addition = " << c << endl ;
    
    system ("PAUSE");
    return 0;
}
This is compiling perfectly on Dev C++

@ Ron

Let me tell u bro, the newer versions, there is no need to use ".h" in names of header files. If u use them, they are considered as backward headers.

But, if u r using OLD TC3 compiler, then it should be there.
Also using namespaces std; will NOT work in that compiler.

Better to go for new standards. U my try Dev C++
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_

Last edited by Garbage; 10-08-2007 at 04:13 PM. Reason: Automerged Doublepost
Garbage is offline  
Old 10-08-2007, 04:55 PM   #17 (permalink)
Ron
||uLtiMaTE WinNER||
 
Ron's Avatar
 
Join Date: Nov 2006
Location: Kathmandu,Nepal
Posts: 698
Default Re: C++:Adding two numbers

Quote:
Originally Posted by shirish_nagar
Let me tell u bro, the newer versions, there is no need to use ".h" in names of header files. If u use them, they are considered as backward headers.

But, if u r using OLD TC3 compiler, then it should be there.
Also using namespaces std; will NOT work in that compiler.

Better to go for new standards. U my try Dev C++
Thnks Bro......i was not knowing this..as I hv also just started C++...probably 7 Days........
Do u hv some basic tutorial.....as I am unable to get the tutorail...........Our School teacher is mad.....She is teaching us carelessly.without giving any notes............It is out of our Ncert course book...........I am studing in class 10......

.. .......Can i get the link of Dev C++................
__________________
||uLtiMaTE WinNER||
Ron is offline  
Old 10-08-2007, 07:35 PM   #18 (permalink)
The Lord of Death
 
Yamaraj's Avatar
 
Join Date: May 2005
Location: यमलोक
Posts: 253
Default Re: C++:Adding two numbers

Quote:
Originally Posted by shirish_nagar
Let me post a good ANSI C++ Program ...

Code:
...
    system ("PAUSE");
...
[snipped...]
Sorry, but this one statement makes your program a nonstandard one.
Read more about it - http://www.gidnetwork.com/b-61.html
Yamaraj is offline  
Old 10-08-2007, 08:11 PM   #19 (permalink)
God of Mistakes...
 
Garbage's Avatar
 
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,905
Smile Re: C++:Adding two numbers

@Ron ,

From HERE u can download Dev C++

Quote:
Originally Posted by Yamaraj
Sorry, but this one statement makes your program a nonstandard one.
Read more about it - http://www.gidnetwork.com/b-61.html
Let me answer some of the things...

Quote:
I've never understood why system("PAUSE") is so popular.
Bcoz it is handy !!!

Quote:
This pause is very useful when your IDE won't wait as you test a program and as soon as the program finished the window closes taking all your data with it.
Thats why I used it !!!

Quote:
t's not portable. This works only on systems that have the PAUSE command at the system level, like DOS or Windows. But not Linux and most others..
Let me tell you, C/C++ programs are NEVER portable. So why to bother for a single statement ???

Quote:
You must include a header you probably don't need: stdlib.h or cstdlib
I think, he must be talking for C, NOT for C++. Bcoz I haven't included those headers.

Hope this is clear now !!!
__________________
Registered Linux User #468778
----------------------------------
http://twitter.com/_Garbage_

Last edited by Garbage; 10-08-2007 at 08:11 PM. Reason: Automerged Doublepost
Garbage is offline  
Old 10-08-2007, 08:17 PM   #20 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,657
Default Re: C++:Adding two numbers

C/C++ sources are portable if you write it for portability (w/o OS sensitive stuff). Programs aren't, right.

Why bother with IDEs and all when you've just started learning. Get a good Linux distro and G++/CC your way through the code.
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 10-08-2007, 09:49 PM   #21 (permalink)
damn busy...
 
utsav's Avatar
 
Join Date: Sep 2006
Location: Jhansi/Meerut
Posts: 1,973
Default Re: C++:Adding two numbers

i am using turbo c++ ver 3.0 from the last 18 months . I am in 12th now and the computer teacher is very impressed from my programming skills.though i don't know programming very deeply but according to ISC board standards it is sufficient.
can any1 tell me from where to download the latest version.I am low on bandwidth that's why i am not downloading the rapidshare link given bu goyal2000. i want 2 download the latest version
__________________
MSI GX660 with ATI 5870 ultimate gaming lappy
Dell Studio 15(1555)
1TB+1.5TB external|N86|ZTE Blade|5230|E63|EP-630|Soundmagic PL50|Sennheiser CXL 400|Meelec M11P+
www.techjunkiez.com
utsav is offline  
Old 10-08-2007, 10:07 PM   #22 (permalink)
C# Be Sharp !
 
Zeeshan Quireshi's Avatar
 
Join Date: Jun 2006
Location: Toronto
Posts: 1,805
Default Re: C++:Adding two numbers

Quote:
Originally Posted by g_goyal2000
Why not simply use Turbo C++???
It's much better & easy to use for starters.

Here's the link to Turbo C++
http://rapidshare.com/files/47910015/TURBOC.EXE

Download it, open the file using Winzip or Winrar and extract it to C: drive.

Be sure to check that the option to use path names is checked otherwise the files will overwrite themselves & u'll have a corrupt complier in your hands.

Do Not execute the file directly by double clicking on it.
No man , coz Turbo C++ is NOT standard C++ . It does not support the ISO C++ Specification and thus is usless in the current context , using any FRee IDE(Visual C++ Express , or borland's free compiler) will be much better.

also , Turbo C++ does NOT run fine under Windows XP(which is what the majority uses)
__________________
There are 10 types of people in the world: those who understand binary and those who do not.
Zeeshan Quireshi is offline  
Old 10-08-2007, 11:11 PM   #23 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default Re: C++:Adding two numbers

Thx Zeeshan for nice info. Can someone sort out the problem I mentioned in Post #13
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
Old 11-08-2007, 11:46 AM   #24 (permalink)
damn busy...
 
utsav's Avatar
 
Join Date: Sep 2006
Location: Jhansi/Meerut
Posts: 1,973
Unhappy Re: C++:Adding two numbers

turbo c++ consumes 100 % cpu on my p4 3 GHz system .unbelievable
__________________
MSI GX660 with ATI 5870 ultimate gaming lappy
Dell Studio 15(1555)
1TB+1.5TB external|N86|ZTE Blade|5230|E63|EP-630|Soundmagic PL50|Sennheiser CXL 400|Meelec M11P+
www.techjunkiez.com
utsav is offline  
Old 11-08-2007, 04:05 PM   #25 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,657
Default Re: C++:Adding two numbers

I think all 16-bit apps do that?

@casanova - Try reinstalling GCC packages? Looks like an incomplete or limited installation which is thus reporting cc1.exe is missing..
__________________
Harsh J
www.harshj.com

Last edited by QwertyManiac; 11-08-2007 at 04:05 PM. Reason: Automerged Doublepost
QwertyManiac is offline  
Old 11-08-2007, 04:36 PM   #26 (permalink)
I am Optimus Prime
 
navjotjsingh's Avatar
 
Join Date: Feb 2005
Location: Delhi, India
Posts: 1,919
Default Re: C++:Adding two numbers

Quote:
Originally Posted by Zeeshan Quireshi

also , Turbo C++ does NOT run fine under Windows XP(which is what the majority uses)
Turbo C++ does run under XP. I run it successfully.
navjotjsingh is offline  
Old 12-08-2007, 03:30 PM   #27 (permalink)
In The Zone
 
Join Date: May 2007
Location: Pune
Posts: 247
Default Re: C++:Adding two numbers

Quote:
Originally Posted by navjotjsingh
Turbo C++ does run under XP. I run it successfully.
I too have problems running Turbo C++ on my Win XP machine. My sister uses it for her 12th class programs. I don't need it, but whenever she tries to make it fullscreen then the whole computers just freezes. (Using Alt+Enter). What you need to do to work it properly?
__________________
Anyone who has never made a mistake has never tried anything new
sandeepk is offline  
Old 12-08-2007, 03:41 PM   #28 (permalink)
Google Bot
 
Pathik's Avatar
 
Join Date: Aug 2005
Posts: 9,751
Default Re: C++:Adding two numbers

Use dev c++..
Pathik is offline  
Old 12-08-2007, 05:15 PM   #29 (permalink)
I am Optimus Prime
 
navjotjsingh's Avatar
 
Join Date: Feb 2005
Location: Delhi, India
Posts: 1,919
Default Re: C++:Adding two numbers

Quote:
Originally Posted by sandeepk
I too have problems running Turbo C++ on my Win XP machine. My sister uses it for her 12th class programs. I don't need it, but whenever she tries to make it fullscreen then the whole computers just freezes. (Using Alt+Enter). What you need to do to work it properly?
Don't run TC using its shortcut. Directly go to bin directory and click on TC.exe I just tested my copy of Turbo C++ and it still works nicely on XP SP2.
navjotjsingh is offline  
Old 12-08-2007, 06:50 PM   #30 (permalink)
The Frozen Nova
 
casanova's Avatar
 
Join Date: Sep 2004
Location: Trespasser in Virtual Land
Posts: 1,641
Default Re: C++:Adding two numbers

@sandeepk

Don't start TC from windows. Go to command prompt, then navigate to tc and then start it from there. U won't have any problem

@qwerty
I had made a full install. Is it coz I am using Vista?
__________________
I dream of a better tomorrow... where chickens can cross roads and not have their motives questioned.

www.nerdweed.blogspot.com
casanova is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
serial numbers of win xp sp2 pravesh_4766 Software Q&A 3 30-04-2006 08:32 PM
Usb pin numbers beyondthegracefgod Peripherals 5 07-11-2004 02:51 PM


All times are GMT +5.5. The time now is 05:57 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2