The Enchanted Cave 2
Delve into a strange cave with a seemingly endless supply of treasure, strategically choos
4.39 / 5.00 38,635 ViewsGhostbusters B.I.P.
COMPLETE edition of the interactive "choose next panel" comic
4.09 / 5.00 15,161 ViewsIs this correct?
yep im a noob :<
#include <iostream>
using namespace std;
Int main ()
{
float;mid;perimeter ;
cout<<"Enter the length of the rectangle";
cin>>len;
cin>>wid;
perimeter = 2*len+2*wid;
cout<<"the perimeter is" ;
cout<< perimeter;
return0;
}
I just started C++ and it's getting me kind of confused... I'm looking for a good compiler too mines going a little weird ;s
visual something? ;s
all fine except these two lines
float;mid;perimeter ;
return0;
float mid, perimeter;
return 0;
and in future, why don't you actually just test it and see if its right or not, and if you can try and figure what is wrong yourself using compiler errors to help;
oh ffs.
That and that you havnt declared wid or len anyway. (im trying to do things too fast again)
perhaps you meant to have wid and len declared, not 'mid'
At 2/27/08 10:05 AM, G-F-D wrote: Int main ()
Int is lowercase. So.. "int main()". VC++ might let you compile it anyway but I'm pretty sure it'd be incorrect.
float;mid;perimeter ;
"float mid, perimeter;" as someone said.
You also need to declare the variables that you use cin to fetch, so:
"float len, wid, mid, perimeter;"
cin>>len;
cin>>wid;
I think "cin >> len >> wid;" is valid. It's easier to write...
cout<<"the perimeter is" ;
cout<< perimeter;
You could just do "cout << "the perimeter is" << perimeter;"
return0;
You need a space between return and 0 unless you use perenthises, so:
"return 0;"
or "return(0);" if you like that better.
I just started C++ and it's getting me kind of confused... I'm looking for a good compiler too mines going a little weird ;s
I use MinGW along with Dev-C++. Dev-C++ destributes a version with MinGW included but it might be better for you to download it along with MSYS on your own to get the latest version. That might be kind of complicated though.
Also, here's what your program would do on Windows outside of a console(if you just run it):
-Freeze and wait for user input without putting anything on the screen.
-Again.
-Display something like "the perimeter is23.45". Note the lack of a space between is and the perimeter.
-Quit instantly before you can actually look the output. The program would work fine in a console though.
To fix some of those quirks, you could write something like(hope the code tag works):
#include <iostream>
using namespace std;
int main() {
float wid, len;
cout << "Enter the width: "; cin >> wid;
cout << "Enter the length: "; cin >> len;
cout << "The perimeter is " << ((wid+len)*2) << "\n";
system("pause");
return 0;
}
Some things to note:
-There's a space or "\n" after everything that goes to cout. The "\n" is a line break and makes cout go to the next line. If you didn't use it, everything would all be on one line. Cin doesn't need a line break after it since it will add one in when you hit enter.
-Cin is a pain in the ass to use. If the input has a space in it, it will be split up into two seperate inputs. If the input isn't of the right type(ex. "abcd" when you cin to a float), cin won't ask for input again. There are ways to fix those involving things like cin.getline(), ect, but keep it in mind.
-"system("pause");". That will run the "pause" program. To see what it does, open the command line by running "cmd" and type pause into the prompt and hit enter. It should ask you to press any key and then return you to the prompt. You can do most things in your program that you can do in the prompt but not all of them which will piss you off to no end. Ex. you can't run web pages in your programs. Pause here will keep your program from ending instantly when you don't run it from a console. You could also use "while(1);" and then hit Ctrl+C to end it which is my preferred method since it doesn't use any functions. If you intend to run it from a command prompt then pause and the infinate loop thing will get in the way.
-Pause will halt your program until the user hits a key and then your program will continue executing where it left off. So, it would then run the "return 0;" thing in my program and end. You can leave off the return statement for the main function and it will return 0. You can't do that for any other function or it will return a random undefined value.
...