I decided to learn C++, and I bought the book "C++ A Beginner's Guide" (this one: http://www.amazon.co.uk/Beginners-Guide-Second-Edition/dp/0072232153) to learn it, as it's getting some nice reviews and its not that expensive. When I started, everything was going fine, until Some problems started to appear. The solutions are probably simple, but I can't find them :(
1 [SOLVED]) I'm using the IDE Code::Blocks, with the compiler MiniGW. It was all working fine for the beginning of the book, until I had to use the abs() function. Basically, Code::Blocks says it's invalid, although I include #include <cstdlib> in the code. What's wrong there? And is there a better IDE I can use? UPDATE: I reinstalled minigw and codeblocks, though the codeblocks + minigw setup. I will say how it went.
2[UNSOLVED]) MiniGW doesn't seem to work when I'm offline, and at random times. Also, it says that the path to my project is invalid, and ld.exe path is invalid. What's wrong there? And what other compiler do you recommend?
3[SOLVED]) I thought that Code::Blocks was the problem, so I installed Visual Express. After making a new Win32 Console project, there's this code which I don't understand:
1 2 3 4 5
|
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
}
|
Normally I thought it's just:
1 2 3 4
|
#include <ioswitch>
using namespace std;
int main(){
}
|
Why is that there in Visual Express?
I tried putting this code in, hoping it would work (as the abs() function isn't working in Code::Blocks, and it doesn't):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int i;
double avg, val;
avg = 0.0;
for(i=0; i<5; i++) {
cout << "Enter a value: ";
cin >> val;
avg = avg + abs(val);
}
avg = avg / 5;
cout << "Average of absolute values: " << avg;
return 0;
}
|
Why is that?
Any help is appreciated :D Thanks for taking your time to read this.