• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VC++ 6.0 or 2005 Express beta?

futuristicmonkey

Golden Member
I have just gotten into programming. Up to now, I've focused on hardware. I found this site which interested me enough to get into it. Since my friend's dad had an unused version of VC++ 6.0, he gave me it, and it's been a lot of fun.

Just today, while helping my sister move, on the way back to my house (my older brother was driving) I made a new program - nothing great, but after the base and height of a triangle are given, it will output the area. It's only been afew days since I started to learn C++.

Anyways, I made this program in VC++ 6.0. But, (I downloaded the VC++ 2005 Express beta) when trying to run it in VC++ 2005, the darn thing won't work! So, after changing #include <iostream.h> to #include <iostream>, I thought it would work. It didn't. So, I then learned that i needed to put std:: before all instances of cout. The darn thing still didn't work :|

I suppose this is a bit of a rant, but I just want to ensure maximum compatability/stability, etc...

Is there any advantage to using the VC++ 2005 beta over VC++6.0? Will there be any problems running programs compiled in 6.0?

Thanks for your time.
 
Originally posted by: notfred
Is this your program? 😛

double area(double base, double height)
{
return base * height / 2;
}

no...

this is it:
#include <iostream.h>

float main(float base, float height)
{
cout << "Enter the base (in cm).\t\t";
cin >> base;
cout << "Enter the height (in cm).\t";
cin >> height;

float Area = base * height / 2;

cout << endl;
cout << "The base is:\t" << base << "cm\n";
cout << "The height is:\t" << height << "cm\n";
cout << "The area is:\t" << Area << "cm^2\n";
return 0;
}

The first time it worked I was so proud of myself 🙂 - it took me so long to figure out the float main(float base, float height) part - i didn't realise I needed to put the things in the brackets.
 
Originally posted by: futuristicmonkey
it took me so long to figure out the float main(float base, float height) part - i didn't realise I needed to put the things in the brackets.

You did that really... wierd. your "main" function says it returns a float, but it doesn't, it returns nothing. It also takes two floats, but isn't actually passed any arguments.

Your function declaration should look like this:
void main()
Instead of:
float main(float base, float height)

Or you could just drop C++ and do it in C#

using System;
namespace ConsoleApplication1
{
class Class1
{
static void Main(string[] args)
{
Console.Write("Enter Base: ");
double baseLength = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter Height: ");
double height = Convert.ToDouble(Console.ReadLine());
Console.WriteLine(baseLength * height / 2);
}
}
}
 
Originally posted by: notfred
Originally posted by: futuristicmonkey
it took me so long to figure out the float main(float base, float height) part - i didn't realise I needed to put the things in the brackets.

You did that really... wierd. your "main" function says it returns a float, but it doesn't, it returns nothing. It also takes two floats, but isn't actually passed any arguments.

Well, when I tried to compile it the first time, I got the error message that base and height were undeclared...then I go the idea to put them in the bracket.

Oh, and when it says it "returns" something..what does this mean? I'm only a few days into this 😱

And what would setting main to "void" do?
 
You should declare base and width inside your function, if that's where they're originating, like this:

void main(){
float base;
float height;

if you put them in the function declaration, like this:
void main(float base, flaot height){

Then any other code that calls this function is expected to send two float values along with it. Here, I'm going to demonstrate functions with some other functions besides "main" since main has some special implications.


// This is main - this is where your code starts
void main(){

// This is a fucntion call look down a little bit to see the function - it's the line that starts "void func1()".
func1();

// Here's another function call, this one returns something - an integer. Look down below func1 for the code for func2.
int myint = func2();

// here's a call to a function that takes an argument, the arguments come in the parentheses following the function name.
// Look for it's decription below.
int anotherint = func3(3);

// this function takes 2 arguments, an integer, and a float. it will return a float. See it's code below as well. Note that it the integer we
// declared in the last line.
float somefloat = func4(anotherint, 3.14);

// This bracket marks the end of the "main" function.
}

// Here is func1 - a function that doesn't do anything. The word void is there because it doesn't return anything.
void func1(){

}

// Here is func2 - it returns an integer, so it's declared with an 'int' type.
int func2(){
return 2;
}

// this is func3, it takes an integer as a parameter, and returns another integer. You can see that it names the integer that it takes "input".
// All this function does is add 1, and then send that data back to the place where the function was called.
int func3(int input){
input = input + 1;
return input;
}

// Here's the code for func4. It takes an int and a float, multiplies them ,and returns a float.
float func4(int someint, float somefloat){
float answer = someint * somefloat;
return answer;
}
 
Originally posted by: notfred
You should declare base and width inside your function, if that's where they're originating, like this:

void main(){
float base;
float height;

First of all, thanks for spending your time writing that! 🙂 I'm going to add this to my favourites list so I can come back to this when I need some explanation.

And, as for the part I quoted, I just realised that I thought (when I wrote the program) that because I put in "cin >> base;" that I didn't need to declare them. Putting base and height into the brackets just seemed right.

Anyways, thanks again for your time.

Oh, and now that I think about it, with the functions that you showed here, when they "return" something..that's only for other parts of the code...that need that function..right?

Because I just used them to output them to the screen with cout. Oh, and when I try to recompile the code with main being void..it tells me that main does return something.
 
Yeah, when a value is "returned" it alllows that value to be used in the code that called it

pretend I have this code:

void main(){
// Here's an integer holding the number of cars in Los Angeles.
int numberOfCarsInLA = 1003030;

// We want to find out how much smog this produces
double smogInLA = amountSmog(numberOfCarsInLA);
}

amountSmog would return a double (A double is a more accurate version of a float). This way we can seperate out the code that figures out how much smog is produced by a certain number of cars. This could be a fairly complex function, and we don't want to include it in our "main" because then it would be hard to read.

Also, if we wanted to, we could do this:
int numberOfCarsInHouson = 1231231;
double smogInHOuston = amountSmog(nuberOfCarsInHouston);

And that way we only need to write a "amountSmog" function once, and we can use it for as many cities as we want. Each time, it "returns" a double to the line of code where we called the function.


Now, "main" is a special case. When main returns, it typically returns an error code to the OS, which is an integer. Usually, 0 means there was no error, and any other number means that there was an error of some type. This is why when a program crashes, you sometimes see a message like "program exiting with status: 1". That means that the main function returned "1".

Similarly, the arguments for main come from the OS, rather than another part of the program. When you type something like "dir /p" the "/p" becomes an argument to main in the code. this is why main typically takes an array of string values for an argument - so you can get any number of paramenters from the command line.
 
Originally posted by: futuristicmonkey
Because I just used them to output them to the screen with cout. Oh, and when I try to recompile the code with main being void..it tells me that main does return something.

You have "return 0;" in there at the end. YOu're returning 0. A void function doesn't return anything, so take that line out.
 
Originally posted by: notfred
Originally posted by: futuristicmonkey
Because I just used them to output them to the screen with cout. Oh, and when I try to recompile the code with main being void..it tells me that main does return something.

You have "return 0;" in there at the end. YOu're returning 0. A void function doesn't return anything, so take that line out.

Well, I'm assuming it doesn't hurt anything, as log as I don't use main as a function for something else (Is that the right way to say that?) if I keep that in there. Is that right?
 
Originally posted by: futuristicmonkey
Originally posted by: notfred
Originally posted by: futuristicmonkey
Because I just used them to output them to the screen with cout. Oh, and when I try to recompile the code with main being void..it tells me that main does return something.

You have "return 0;" in there at the end. YOu're returning 0. A void function doesn't return anything, so take that line out.

Well, I'm assuming it doesn't hurt anything, as log as I don't use main as a function for something else (Is that the right way to say that?) if I keep that in there. Is that right?

If the function is of type "void" and it returns a value, then the compiler will give you an error. YOu either have to have a return type, or not return anything.
 
btw, vs2005's C++ compiler is probably a bit more standards-compliant than vc6. they certainly made improvements to being standards-compliant from vc6 to vs2003. for your purposes, it really won't matter either way though.
 
Back
Top