GrinderMJ 0 Posted February 1, 2007 Share Posted February 1, 2007 Ok, so I have to write a basic program for C++ and I've been working on it for hours and have gotten nowhere, i was wondering if any of you had any computer programming background and could help me figure out where I'm going wrong: here is what I've got so far, as well as my errors://My Name//CSCI1010 //Programming Assignment //January 31, 2006/*This program will request a length and width from the keyboard, calculate the area of a rectange with those dimensions, and display to the monitor length, width, and area in tabular form.*/#include <iostream>using namespace std;int main( ){ int width, height; cout << "Enter Rectangle Width: "; cin >> width; cout << "Enter Rectangle Height: "; cin >> height; area = width * height; perimeter = 2 * width + 2 * height; cout << "area: "; cout << "perimeter: "; return 0;}~~"pass2.cpp" 24L, 580C written [myname@cscilinux2 myname]$ g++ pass2.cpppass2.cpp: In function `int main()':pass2.cpp:18: `area' undeclared (first use this function)pass2.cpp:18: (Each undeclared identifier is reported only once for each function it appears in.)pass2.cpp:19: `perimeter' undeclared (first use this function) Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 Here are updated errors:"pass2.cpp" 24L, 580C written [myname@cscilinux2 myname$ g++pass2.cpp-bash: g++pass2.cpp: command not found[myname@cscilinux2 myname]$ g++ pass2.cpppass2.cpp: In function `int main()':pass2.cpp:18: `area' undeclared (first use this function)pass2.cpp:18: (Each undeclared identifier is reported only once for each function it appears in.)pass2.cpp:19: `perimeter' undeclared (first use this function)[myname@cscilinux2 myname]$ Link to post Share on other sites
Magsugal 0 Posted February 1, 2007 Share Posted February 1, 2007 you need to put area and perimeter as an integarso int width, height, area, perimeter;let me think about it for a while Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 you need to put area and perimeter as an integarso int width, height, area, perimeter;let me think about it for a whileWhen I added that and compiled, no errors came up but it's like the program didn't try to run, now I'm relaly confused. Link to post Share on other sites
Magsugal 0 Posted February 1, 2007 Share Posted February 1, 2007 i don't remember a ton of c++try putting #include<iostream.h> Link to post Share on other sites
onlyme386 0 Posted February 1, 2007 Share Posted February 1, 2007 try...int width = 0;int height = 0;int area = 0;int perimeter = 0;....Sometimes you need to zero the values for area and perimeter for the program to work.also at the beginning...#include "stdafx.h" Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 i don't remember a ton of c++try putting #include<iostream.h>This caused a massive error. I took it out and added Onlyme's suggestion and the program again came up with no errors, but failed to run. I have no idea what that means. Link to post Share on other sites
onlyme386 0 Posted February 1, 2007 Share Posted February 1, 2007 add...#include <cmath>on the line with the int main() you need to add something inside the brackets. I believe what you need is... int argc, char* argv[] Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 OK, I'm sort of an idiot and I'm getting really close. I managed to compile the program, but forgot to run it. Ya, I'm smart like that. Anyways, when I add onlyme's additions it runs the output asking me for the width/height, but when I hit enter, it doesn't calculate the area and perimeter, what am I missing? Link to post Share on other sites
onlyme386 0 Posted February 1, 2007 Share Posted February 1, 2007 OK, I'm sort of an idiot and I'm getting really close. I managed to compile the program, but forgot to run it. Ya, I'm smart like that. Anyways, when I add onlyme's additions it runs the output asking me for the width/height, but when I hit enter, it doesn't calculate the area and perimeter, what am I missing?hit on me AIM, onlyme386much easier. Link to post Share on other sites
Magsugal 0 Posted February 1, 2007 Share Posted February 1, 2007 u didn't cout area and perimeter anywhere. Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 Here's the whole shebang thus far.//Programming Assignment 2//January 31, 2006/*This program will request a length and width from the keyboard, calculate the area of a rectange with those dimensions, and display to the monitor length, width, and area in tabular form.*/#include<iostream>using namespace std;int main( ){ int width = 0; int height = 0; int area = 0; int perimeter = 0; cout << "Enter Rectangle Width: "; cin >> width; cout << "Enter Rectangle Height: "; cin >> height; area = width * height; perimeter = 2 * width + 2 * height; cout << "area: "; cout << "perimeter: "; return 0;}~"pass2.cpp" 27L, 627C written [myname@cscilinux2 myname]$ g++ pass2.cpp[myname@cscilinux2 myname]$ ./a.outEnter Rectangle Width: 12Enter Rectangle Height: 9area: perimeter: Link to post Share on other sites
Magsugal 0 Posted February 1, 2007 Share Posted February 1, 2007 cout << "area: ", area;cout << "perimeter: ", perimeter; Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 Wow thanks for the help guys, I finally got it!!!!!!!!!!! Wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee Link to post Share on other sites
Magsugal 0 Posted February 1, 2007 Share Posted February 1, 2007 Cool. C++ isn't too hard after u get into it. Link to post Share on other sites
dna4ever 2 Posted February 1, 2007 Share Posted February 1, 2007 Wow thanks for the help guys, you finally got it!!!!!!!!!!! Wheeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeefyp Link to post Share on other sites
Jeepster80125 0 Posted February 1, 2007 Share Posted February 1, 2007 I'm a little late, but I would have folded preflop and paid my IT guy.Just sayin'. Link to post Share on other sites
Dirtydutch 8 Posted February 1, 2007 Share Posted February 1, 2007 01001001-01110100-00100000-01101001-01110011-00100000-01110011-01101111-00100000-01110011-01100001-01100100-00100000-01110111-01100001-01110100-01100011-01101000-01101001-01101110-01100111-00100000-01111001-01101111-01110101-00100000-01100111-01110101-01111001-01110011-00100000-01100110-01101111-01101100-01100100-00100000-01110100-01101111-00100000-01100011-01101111-01101101-01101101-01111001-00100000-01110000-01110010-01100101-01110011-01110011-01110101-01110010-01100101-00100000-01100001-01101110-01100100-00100000-01110101-01110011-01100101-00100000-01000011-00100000-01110000-01101100-01110101-01110011-00100000-01110000-01101100-01110101-01110011-00100000-01110010-01100101-01100001-01101100-00100000-01110000-01110010-01101111-01100111-01110010-01100001-01101101-01101101-01100101-01110010-01110011-00100000-01110101-01110011-01100101-00100000-01100010-01101001-01101110-01100001-01110010-01111001- Link to post Share on other sites
zsta2k6 0 Posted February 1, 2007 Share Posted February 1, 2007 Here are updated errors:"pass2.cpp" 24L, 580C written [myname@cscilinux2 myname$ g++pass2.cpp-bash: g++pass2.cpp: command not found[myname@cscilinux2 myname]$ g++ pass2.cpppass2.cpp: In function `int main()':pass2.cpp:18: `area' undeclared (first use this function)pass2.cpp:18: (Each undeclared identifier is reported only once for each function it appears in.)pass2.cpp:19: `perimeter' undeclared (first use this function)[myname@cscilinux2 myname]$Always instantiate your variables Link to post Share on other sites
GrinderMJ 0 Posted February 1, 2007 Author Share Posted February 1, 2007 fypTrue, I had a lot of it though, but onlyme was clutch. Link to post Share on other sites
Wandigo 1 Posted February 1, 2007 Share Posted February 1, 2007 no kudos for your boy wandy for doing your homework for you? Link to post Share on other sites
Suited_Up 2 Posted February 1, 2007 Share Posted February 1, 2007 This would help.... Link to post Share on other sites
onlyme386 0 Posted February 1, 2007 Share Posted February 1, 2007 True, I had a lot of it though, but onlyme was clutch.tyty, anytime.no kudos for your boy wandy for doing your homework for you? See above. Link to post Share on other sites
coesillian 0 Posted February 1, 2007 Share Posted February 1, 2007 I have some assignments and 6 power point lecture notes on a few chapters from the C++ book we used in my university course. I can send them if you're interested. Link to post Share on other sites
thebamaman 0 Posted February 1, 2007 Share Posted February 1, 2007 Let's change it for a little better style (I changed what's in the quote). You should declare variables as late as possible, only C makes you declare variables at the beginning of a function. Here you see area and perimeter are declared the first time they are used, and they are initialized when declared (never declare an unitialized variable if you can help it).It also seems like you forgot some of the parts of the assignment "display to the monitor length, width, and area in tabular form"! //Programming Assignment 2//January 31, 2006/*This program will request a length and width from the keyboard, calculate the area of a rectange with those dimensions, and display to the monitor length, width, and area in tabular form.*/#include<iostream>using namespace std;int main( ){ int width = 0; int height = 0; cout << "Enter Rectangle Width: "; cin >> width; cout << "Enter Rectangle Height: "; cin >> height; int area = width * height; int perimeter = 2 * width + 2 * height; cout << "area: " << area << "perimeter: " << perimeter << endl; return 0;} Link to post Share on other sites
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now