Dev-C++ not working

Pages: 12
I'm running Windows 98 (just to get that out of the way).

Hello again,

I snagged a copy of C++ for Dummies from the library and was typing the first example program into Dev-C++. After numerous errors, I finally got the code right, but when I ran it, instead of displaying the text it was supposed to, it just showed "Press any key to continue..." I was sure I got the code right, so I figured it was the compiler's fault and just moved on.

About half-way through the first section of Chapter 2, I got inspiration to make a simple 'average of three numbers' program. The result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//
//  Program to find the 
//  average of three numbers
//

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
	cout << "This program will find the average of three numbers.";
	
	// enter the numbers you want
	// to find the average of
	double valueOne; double valueTwo; double valueThree;
	cout << "Enter the first number:";
	cin >> valueOne;
	cout << "Enter the second number:";
	cin >> valueTwo;
	cout << "Enter the third number:";
	cin >> valueThree;

	// calculate the average
	// of the numbers
	double average;
	average = (valueOne + valueTwo + valueThree) / 3;
	cout << "The average is:";
	cout << average << endl;
    
	return 0;
}


(Let me add here that the displayed text came out as one line; if the solution is easy, could you let me know what it is?)

It looked pretty good to me and the IDE said there were no errors, so I tried to run it. It displayed "Press any key to continue..." and patiently waited for my input. By then it was starting to annoy me and I figured that I couldn't learn a programming language if I couldn't run any of my programs. So I went to a friends house (who's father programs as a hobby) and entered the same code in Visual C++ 6.0, and the program ran just fine ('cept the no breaks in the line, but that of course is because I'm an idiot).

So that is my problem. Is there a soulution? Maybe an alternate IDE (I could steal VCPP6 (<<is that a valid acronym?) from the friend?)?

I'll also add that the programs ran fine in debug mode (which I pressed by mistake).

Any help is appreciated.
Last edited on
Try "Compile and Run".
No difference.

This is starting to piss me off. I'd rather not switch IDEs because the book is written assuming you're using Dev-C++.
The above program worked OK in Dev-C++ for me 9using Windows XP Pro).

I added
cin.get();
cin.get();

before the return so that the program would halt and wait for a character input before closing. [There are better ways of doing this.]

I also added " << endl " at the end of line 13.

Alan
endl = end line
duh...

Alright I've got an XP as well, I'll give it a try on that computer.

Thanks for the help.
Alright, I've got a few more questions that I didn't think where threadworthy. First of all, here is the new and improved version of the program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//
//  Program to find the 
//  average of three numbers
//

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;

int main(int nNumberofArgs, char* pszArgs[])
{
	cout << "This program will find the average of three numbers.." << endl;
	cout << "..because we all know you're too stupid to do it yourself." << endl;
	cout << " " << endl;
	
	// enter the numbers you want
	// to find the average of
	double valueOne; double valueTwo; double valueThree;
	cout << "Enter the first number, dummy: ";
	cin >> valueOne;
	cout << " " << endl;
	cout << "Enter the second number, stupid: ";
	cin >> valueTwo;
	cout << " " << endl;
	cout << "Enter the third number, retard: ";
	cin >> valueThree;
    cout << " " << endl;

	// calculate the average
	// of the numbers
	double average;
	average = (valueOne + valueTwo + valueThree) / 3;
	cout << "The average is ";
	cout << average;
	cout << ", you idiot." << endl;
    
	return 0;
}


Shut up, I'm having fun.

Anyways notice the "cout << " " << endl;" lines. Is there a simpler way to do this?

And can someone explain the whole 'workspace, project, blah blah blah' of Visual C++ 6.0? I think they made that waaaay more complicated than it needs to be. I just want to be able to do the exercises and mess around without too much clutter (and be able to get to the files later, of course).
cout << endl;
cout << "\n";
either work.
Testing aaaand..
works perfect! Thank you very much.
Small tip:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
cout << "This program will find the average of three numbers.." << endl;
cout << "..because we all know you're too stupid to do it yourself." << endl;
cout << " " << endl;
//is the same as
cout <<"This program will find the average of three numbers..\n..because we all know you're too stupid to do it yourself.\n\n";
//If you care about readability, you can also do it like this:
cout <<"This program will find the average of three numbers..\n"
       "..because we all know you're too stupid to do it yourself.\n\n";
//Not really sure if there's any performance gain in doing it like this, but
//what the hell? It can't hurt, can it?


//You can also do
cout << "The average is "<< average<< ", you idiot." << endl;

I think the console should put a new line after every std::cin.
Last edited on
Ahh that makes sense. Keep in mind my limited knowledge though. I've read about a chapter and 1/8 in the book lmao.

Edit: Question: when should I use "<< endl;" and when should I use "/n"?
Last edited on
It is your choice!! But use "\n" NOT "/n"!!!

Alan
I did keep it in mind.
std::endl is portable.
...I think.
It wouldn't make much sense to have it, otherwise.
Win32 and Linux treat them as equivalent, but it wouldn't surprise me if there was some weird platform out there using '\t' as a line breaker.
One compiler used to complain when I used std::endl if there were more things left to output in the same statement. Or at least I think it did. Lately they seem to be rather indifferent.
Edit: Forget I said anything.

And thank you to all who responded!
Last edited on
Edit: Question: when should I use "<< endl;" and when should I use "/n"?


It's "\n" as stated. But there is actually a difference.

\n will output a newline character into the stream. This should work on all platforms.

endl will output an endline character and then flush the stream to be displayed. If you do not flush the screen then nothing will be displayed.


It's upto you which one you use. I will often use \n for the most part and use endl on the last command in a setup of IOStream writes (saves work when writing to a file). This means the buffer to my file is only going to be flushed once I have finished filling it with information instead of multiple-times (speed thing).

HTH, sorry for quick explanation. Took me all of 15secs to type that.
:headexplodes

Alright, I'll keep that in mind for when I understand all teh vocabz.
Seeing as this has turned into a "My idiotic first couple days questions" thread, I've got a few more for ya vets:

Why would you use 'int' when you can use 'double'. Apparently C++ can't count with double values, but what exactly does that mean? Also, the book talks about round-off error and says:

"C++ can correct for many forms of round-off error. For example, in output, C++ can determine that instead of 0.999999, that the user really meant 1. In other cases, even C++ cannot correct for round-off error."

How is ^that^ "correcting"? It seems as though C++ is saying "I know best". Maybe the user wanted 0.999999?

That's all for now.
You could use doubles instead of Ints throughout all the code, but why?
double requires more memoryspace than int.. You should only use the largest variable that you need.

I mean, I could use an old banana box to mail an envelope, but why?

as for the second question, I've never run across that. I now that an int, or double doesn't hold decimal points, you need a float for that. If you try to put 0.999999 into an int, you'd get 0 (it doesn't round, it simply cuts off everything after the decimal). So I'm unsure what you mean by that.
Ehh because there're alot of decimals in math, so it makes sense that every value should be capable of having decimal places.

And I think the book is just wording stuff wrong. I'm assuming it's non-essential information and just moving on.
You could use doubles instead of Ints throughout all the code, but why?
double requires more memoryspace than int.. You should only use the largest variable that you need.


Double's are also inaccurate and slower to work on.

as for the second question, I've never run across that. I now that an int, or double doesn't hold decimal points, you need a float for that.


Doubles hold decimal points. What you need to be aware, as Aakanaar has said is that when converting a double to an int it will chop off everything after the decimal point. But when working in doubles they are inaccurate and doing something like if (double1 == double2) may fail if even if they are both 1.2 (because double1 maybe 1.20000000000001 etc).

Only use a double/float when you need to work with decimal values. Otherwise stick to an int.

oooh.. ok.. doubles do hold decimal points.. didn't realize that. sorry, my bad. I think I was confusing a double with a long. that's what I did. sorry.
Pages: 12