# Help adding numbers in C++



## ©mß (Apr 17, 2013)

This code is what I wrote.
After typing first no. and then the second no. and then when I press enter, no result is shown and program terminates.
What is wrong in the code?
Our teacher asked to add ourselves using our BRAIN.
I am unable to understand,is this method right?

I am right now using Turbo C++.
So,do i have to press Alt+F5 to get the ans or it should give me ans when I press Cntrl+F9?


----------



## harshilsharma63 (Apr 17, 2013)

The code is perfect but the problem is the lord or crap Turbo C. Just make the program in some IDE and it will run. ANd please please ^100000000000 stop using turbo C


----------



## coderunknown (Apr 17, 2013)

can't help. most university still recommend using this ancient stuff. learned C++ this way just to pass and get the first step in world of programming.


----------



## krishnandu.sarkar (Apr 17, 2013)

Well I agree, Turbo C is crap but students have no way, as universities and colleges force it.

@OP replace...

int main() with void main()

and return 0; with getch();


----------



## nightcrawler (Apr 17, 2013)

Stop using Turbo C++. It uses all non standard function calls. Why are you using conio.h? Stop using it. It is non-standard library. Also don't use clrscr(). Again Same non-standard function. Also I would not recommend using getch(), again a non standard function.  While you may ask as to why not to use them. Using such calls generally creates a habit that tends to continue as you go along. If you are serious about programming as a career, then start using standard C++ practices in your code. It will help you believe me.

God Why do they use Turbo C++ still especially when good free compilers and IDEs are available?

Use the following code snippet


```
#include <iostream>
#include <limits>

int main(int argc, char*argv[])        {
      //Code Start
      //Code Goes here
      //Cod End
      cin.ignore( numeric_limits<streamsize>::max(), '\n' );
      return iValue; // your main function return value to system
}
```

That should work for you.


----------



## harshilsharma63 (Apr 18, 2013)

@OP; even if your college used TurboC, even then you should use Code::Blocks or (the better) Eclipse.


----------



## krishnandu.sarkar (Apr 18, 2013)

nightcrawler said:


> Stop using Turbo C++. It uses all non standard function calls. Why are you using conio.h? Stop using it. It is non-standard library. Also don't use clrscr(). Again Same non-standard function. Also I would not recommend using getch(), again a non standard function.  While you may ask as to why not to use them. Using such calls generally creates a habit that tends to continue as you go along. If you are serious about programming as a career, then start using standard C++ practices in your code. It will help you believe me.
> 
> God Why do they use Turbo C++ still especially when good free compilers and IDEs are available?
> 
> ...



Well, I doubt whether this piece of code will get accepted by the college.

But I agree with you and others. Like we all said, what I suggested is non standard programming and one should not practice it.

But another truth is that, there's no way if you are a college student and have to submit assignments. So as harshilsharma63 said, use Code::Blocks at home for practicing and modify the code for submission.


----------



## nightcrawler (Apr 18, 2013)

That is a cause of concern then. The education, especially the IT education in India sucks big time. No scope for creativity and thinking out of the box, I remember the time when some of us tried coding in different ways, the faculty used to give less marks (sometimes 0) simply because it was "not a proper way to code" and did not match the code given in the book or something. It was more of a case of them not understanding the code...oh things haven't changed over the years I guess...


----------



## Nerevarine (Apr 18, 2013)

OBSTINATE TEACHERS !!!!!!!!!!!!
I hated TC because of the damn blue screen


----------



## harshilsharma63 (Apr 18, 2013)

Nerevarine said:


> OBSTINATE TEACHERS !!!!!!!!!!!!
> I hated TC because of the damn blue screen


At least in dept. (CSE), turbo C is officially banned. If a student is found to have used Turbo C for making project or any assignment, his/her marks are deducted!


----------



## ©mß (Apr 18, 2013)

Well this is my first ever code written by me on my second class.
So,my teacher taught us to write in this way just asked us to add on our own.
I too hate that bright eye penetrating BLUE colour.


----------



## harshilsharma63 (Apr 18, 2013)

©mß said:


> Well this is my first ever code written by me on my second class.
> So,my teacher taught us to write in this way just asked us to add on our own.
> I too hate that bright eye penetrating BLUE colour.


If thats the case, you are still far from becoming used to the non-standard functions in the crap. Switch to Code Blocks of Eclipse.


----------



## krishnandu.sarkar (Apr 18, 2013)

©mß said:


> Well this is my first ever code written by me on my second class.
> So,my teacher taught us to write in this way just asked us to add on our own.
> I too hate that bright eye penetrating BLUE colour.



Well that's good. Your teacher is teaching you the standard way of writing C programs.

In that case do what @nightcrawler  suggested.


----------



## gameranand (Apr 19, 2013)

Well I just use Code::Blocks and if some teacher ask me to write in Turbo then I just ask them to install Code::Blocks and usually they don't ask again.


----------



## ©mß (Apr 22, 2013)

Spoiler






So,why is this error coming?
I created the .exe file with Turbo C++ of whose screenshot I posted earlier.

Moreover, how do you insert image in spoiler?
I tried but failed as you can see. LOLS


----------



## harshilsharma63 (Apr 22, 2013)

©mß said:


> Spoiler
> 
> 
> 
> ...



> My hypothesis: TurbiC is a 16 bit program so the EXEs generated by it are also 16 bit which cannot be run on a 32/64 bit machine.

> Enclose the link to the image in IMG tags: 
	

	
	
		
		

		
		
	


	




> You still haven't switched to an IDE.


----------



## Shah (Apr 22, 2013)

©mß said:


> Spoiler
> 
> 
> 
> ...



We already told you that TC++ is just a peice of carp and not to use it. Anyway, Try running that compiled program in Win95 or Win98. It would work.


----------



## harshilsharma63 (Apr 22, 2013)

Shah said:


> We already told you that TC++ is just a peice of carp and not to use it. Anyway, *Try running that compiled program in Win95 or Win98*. It would work.


Yeah, it's meant for that


----------



## ©mß (Apr 23, 2013)

I downloaded eclipse for C++ and when I typed all the lines same as of TC++, it is not accepting them.
It says like cout,cin is not supported.
Is it different in eclipse

I changed the compatibility to Win95&98.
Still same error persists.


----------



## nightcrawler (Apr 23, 2013)

©mß said:


> I downloaded eclipse for C++ and when I typed all the lines same as of TC++, it is not accepting them.
> It says like cout,cin is not supported.
> Is it different in eclipse



I am sure you have missed putting

```
using namespace std;
```
at the top of your code. See what Turbo C++ does for you?

Add the above bit and your code should work just fine in eclipse. Remember that Eclipse is just an IDE (Integrated Development Environment). It will follow the syntax grammer of that language for which it has been configured. So no, it is not differenct in eclipes. These are C++ specific syntax. Since cin, cout etc are part of std namespace you have to either reference that  in your code or specify something like std::cin etc. Readup a bit on namespaces and their uses etc as well.


----------



## harshilsharma63 (Apr 23, 2013)

©mß said:


> I downloaded eclipse for C++ and when I typed all the lines same as of TC++, it is not accepting them.
> It says like cout,cin is not supported.
> Is it different in eclipse
> 
> ...



the structure of the program is:

<preprocessors>
<definations>
<main function>

write it as: 
	
	



```
#include<iostream>
using namespace std;

int main()
{
     cout << "blah blah blah...";
     return 0;
}
```

remember, its "iostream", not "iostream.h".


----------



## ©mß (Apr 26, 2013)

Now bye-bye to TC++.
Now we'll learn Python.
CBSE ordered to teach Python instead of C++ for it's more demand in market.


----------



## harshilsharma63 (Apr 26, 2013)

©mß said:


> Now bye-bye to TC++.
> Now we'll learn Python.
> *CBSE ordered to teach Python instead of C++ for it's more demand in market.*


 I wonder when will my university will come to know about the reality.


----------



## ©mß (Apr 26, 2013)

If it's implemented here then next might be your university.
BTW which university? DU?


----------



## harshilsharma63 (Apr 26, 2013)

©mß said:


> If it's implemented here then next might be your university.
> BTW which university? DU?


Rajasthan Technical University.


----------

