Help adding numbers in C++

©mß

Journeyman
Dos.PNG
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?
 
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 :pullhair::pan::sniper::flamethrower:
 

coderunknown

Retired Forum Mod
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

Simply a DIGITian
Staff member
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

Broken In
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

Code:
#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.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
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

Code:
#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.

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

Broken In
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...:-(
 
OP
©mß

©mß

Journeyman
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 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

Simply a DIGITian
Staff member
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

Living to Play
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. :D:D
 
OP
©mß

©mß

Journeyman
exe file.PNG
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
 
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

> 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

Cyborg Agent
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

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.
 
OP
©mß

©mß

Journeyman
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

Broken In
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
Code:
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.
 
Top Bottom