Hello, not too long ago I got a Beginning Programming with C++ For Dummies book from my local library. Inside the book there was a CD which installs Code::Blocks onto my computer. I installed it and have made multiple programs that the C++ For Dummies book taught me.
I would read what he said up to the program, then write the program exactly as he did. Then I would build it, then run it. The different programs, like the Hello World! one, would always work.
I learned that I could build and run the program by pressing F9, so I often did that instead of clicking the build and run button. Well, at one point, I built a program and ran it and it worked fine, then I went to click F9 again, but I accidently pressed F8, which starts the debugger. I wasn't sure what I did, but I figured out that I turned the debugger on. On the bottom where it would usually show whether there were any errors or anything, it showed something I didn't understand (I think it was telling me what it was debugging). So, I tried to build and run the program again, but it said the debugger was currently working/active/whatever and asked if I wanted to stop it, I clicked yes, but it said that it could not stop the debugger. So, I just closed C::B. I went back on C::B and everything seemed fine and dandy, so I made another program. I built it, I ran it, it worked fine, but then I ran it again and instead of saying "This program calculates the factorial of an entered number. Please enter number:_", it just showed the blinking white cursor/underscore/_, which made me think it wanted me to type something, but I pushed everything and nothing happened. I tried to end the program by pressing enter, but nothing happened, even when I pressed it twice.
In other words, my program wasn't working or responding, even though my code was the same. I had no choice but to close the window, so it said below that the program was terminated, but the window didn't close. Then my Norton Anti Virus said SONAR has detected a high security risk in "[insert name of program here].exe", then it said it deleted the security risk, your computer is safe. So, then I trashed the program and created a new one. I built it, ran it, it worked fine, but I ran it again, and it didn't show my program again, and wouldn't work.
Why is it doing this? I use GNU GCC Compiler, it's a C++ Console Application program. I have Windows 7 (I don't think I have premium), I don't know how to check to see which version of C::B I have. Also, when I try to use a program after bringing it up with recent files, it will immediately go to the security risk, underscore showing, thing.
I want to make programs that I can use more than once, what did I do wrong? Can I fix this? How? I appreciate any helpful answer.
Here's a sample code it won't let me run: //
// FunctionDemo - demonstrate how to use a function
// to simplify the logic of the program.
//
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
//
// sumSequence() - return the sum of a series of numbers
// entered by the user. Exit the loop
// when the user enters a negative
// number.
int sumSequence()
{
// create a variable into which we will add the
// numbers entered by the user
int nAccumulator = 0;
for(;;)
{
// read another value from the user
int nValue;
cout << "Next: ";
cin >> nValue;
// exit if nValue is negative
if (nValue < 0)
{
break;
}
// add the value entered to the accumulated value
nAccumulator += nValue;
}
// return the accumulated value to the caller
return nAccumulator;
}
int main(int nNumberofArgs, char* pszArgs[])
{
cout << "This program sums sequences of numbers.\n"
<< "Enter a series of numbers. Entering a\n"
<< "negative number causes the program to\n"
<< "print the sum and start over with a new\n"
<< "sequence. "
<< "Enter two negatives in a row to end the\n"
<< "program." << endl;
// stay in a loop getting input from the user
// until he enters a negative number
for(;;)
{
// accumulate a sequence
int nSum = sumSequence();
// if the sum is zero...
if (nSum == 0)
{
// ...then exit the program
break;
}
// display the result
cout << "Sum = " << nSum << endl;
}
// wait until the user is ready before terminating the program
// to allow the user to see the program results
system("PAUSE");
return 0;
}