I am new to c++. I made a calculator and i "build and run" it and it worked perfectly. then I tried to run the program that was created by the compiler and when I put in the numbers and hit enter the program just shuts down without showing the answer can someone help me?
I use codeblock
#include <iostream>
#include <limits>
using namespace std;
int num1, num2, result;
int main()
{
cout << "Welcome! please enter a number!" << endl;
What OS are you running it on? Is it possible you've downloaded the IDE from an outdated source? http://forums.codeblocks.org/index.php?topic=9912.0 <- this suggests that pause after run is turned off by default and can be turned on under project preferences. (Not the default setting on my Linux machine, but here it actually opens xterm, so that's not saying much)
the std::cin.get(); line worked. what is the function of that line?
I have also been serching for a way to make the program start over again after the equation is finished and not just shut down. I have tried to see if the loop functions can help me, but I have not had any luck with that.
cin.get (); <-this says to wait for the user to input a single character. Usually you would set a char type variable using it, but here we are ignoring the actual content that it returns.
Loops are what you are needing to make the program run multiple times, look into them a bit further. They run everything in their block over and over until the given condition is met. They must be inside of another function like main, they are not functions in themselves.
While loops and for loops are the main ones, though there are for-each and do-While loops later on.