Web Hosting Talk







View Full Version : Does this look OK? (C++)


WoodShedd
01-17-2003, 01:12 AM
The other day I bought a hat in a thrift store. I washed it 3 times and its still stinky.

I also bought a relatively new looking college textbook on C++. I've always wanted to learn a new language, but i prefer speaking to things that can't not listen. That ruled out most languages spoken by humans.

anyway I read the first two chapters and decided to try my hand at a (simple) program.

I dont have a compiler so I dont know this runs or works. would any of you experienced programmers be able to tell by looking at it? just a note that i put in stdafx.h because the book mentioned it


// foil.cpp : The program will expand equations of the type (ax+b)(cx+d)
//

#include "stdafx.h"
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
int first, inside, outside, last;
int term1, term2, term3;

cout << "(ax+b)(cx+d)" <<endl;
cout << "Please enter a, b, c and d, respectively. Press enter after you are done:";
cin >> first >> inside >> outside >> last;

term3 = inside * last;
term2 = (first * last) + (inside * outside);
term1 = first * outside;

cout << "(" << first << "x" << "+" << inside << ")" << "(" << outside << "x" << "+" << last << ")" <<endl;
cout << "the above expands to:" << endl;
cout << term1 << "x^2" <<"+" << term2 <<"x" <<"+" << term3 <<endl;


return 0;
}


thanks for any help

banner
01-17-2003, 01:45 AM
It looks ok. Maybe a little later I'll fire up VC++ .NET and check it out for you. The one thing that stands out is that you should not have the #include "stdafx.h" line in there unless you actually use that file. For the most part, unless you're using VC++, you don't need it (and even then you can leave it out with some minor project tweaks).

If you're running a Windows machine, I'd recommend going out and picking up a copy of Visual C++ 6.0 or .NET. If you have a local Half Price Books, they may have 6.0. Otherwise the learning edition of Visual C++ .NET is relatively inexpensive at your local computer book store ($50-$90, I think). If money is an issue, look at installing Cygwin. That's free and will let you run g++ to compile code. That'll let you know if your code works correctly.

I hope this helps.

banner
01-17-2003, 02:47 AM
Ok, I compiled and ran your code under Visual C++ .NET and it works fine.

Good luck with learning!

WoodShedd
01-17-2003, 03:07 AM
thanks banner, I appreciate it.

Can you recommend a good compiler/linker that is free. I cannot afford VC++

banner
01-17-2003, 04:17 AM
If you need a free one, I'd look at installing Cygwin. It's basically a unix environment for windows that allows you to run g++ (the standard linux C++ compiler) and a few other Linux programs. You can find out more information at www.cygwin.com.

A couple of other free compilers are DJGPP (http://www.delorie.com/djgpp/) and Borland 5.5 (http://www.borland.com/products/downloads/download_cbuilder.html). I can't vouch for how well any of these work as I've only really used VC++ extensively, but they should give you some places to start.

I hope this helps.

aah-jim
01-18-2003, 08:02 AM
try DevC++
i like it
can't remember the url though :blush:

ToTheMax
01-18-2003, 09:57 AM
Originally posted by jimcarter
try DevC++
i like it
can't remember the url though :blush:

The URL is http://www.bloodshed.net