Flash Website Builder- Trendy Site Builder is a Flash Site Building tool that helps users build stunning websites. Check Out Custom Custom Logo Design by LogoBee. Website Design and Free Logo Templates available.
 CodingForums.com Rectangle Program

Before you post, read our: Rules & Posting Guidelines

Enjoy an ad free experience by logging in. Not a member yet? Register.
 09-10-2013, 06:12 PM PM User | #1 tylergray New to the CF scene   Join Date: Sep 2013 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts Rectangle Program Hi all, I am currently trying to create a code that will allow me to do the following: Enter length vs. width of a rectangle Receive area + perimeter values I was given a solution template to get me started: /* File rectangle.c Given the dimensions of a rectangle in metres, compute its area and perimeter length. Programmer: Date: */ #include int main(void) { int x, y, area, perimeter; printf("Dimensions of the rectangle (rounded to nearest metre): "); /* you fill in the rest */ system("pause"); /* omit this line on Mac's */ return 0; } I cannot seem to figure this out with the given template, however I was able to create a code that allows me to get the area by entering l*w and all I would have to do from there was add another code which will allow the user to input 2 lengths and receive the perimeter. But I am worried my professor will expect me to use his template. Here is MY version of the code which is half complete: #include using namespace std; int mult ( int l, int h ); int main() { int x, y, area, perimeter; printf("Dimensions of the rectangle (rounded to the nearest metre) : "); int l; int h; cout<<"Enter length, height: "; cin>> l >> h; cin.ignore(); cout<<"The area of your rectangle is "<< mult ( l, h ) <<"\n"; } int mult ( int l, int h ) { return l * h; } And here is the one I attempted off of his template: /* File rectangle.c Given the dimensions of a rectangle in metres, compute its area and perimeter length. Programmer: Date: */ #include int main(void) { int x, y, area, perimeter; printf("Dimensions of the rectangle (rounded to nearest metre): "); int mult ( int l, int h ); int main() { int x, y, area, perimeter; printf("Dimensions of the rectangle (rounded to the nearest metre) : "); int l; int h; cout<<"Enter length, height: "; cin>> l >> h; cin.ignore(); cout<<"The area of your rectangle is "<< mult ( l, h ) <<"\n"; } int mult ( int l, int h ) { return l * h; } I basically just migrated them. I have zero experience with C++, It's just a req in my first year of engineering. Any pointers will be greatly appreciated. Thanks! system("pause"); /* omit this line on Mac's */ return 0; }
10-10-2013, 01:04 PM   PM User | #2
KenJackson
New Coder

Join Date: Aug 2010
Location: Maryland, USA
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
 Originally Posted by tylergray #include using namespace std; ... cout<<"Enter length, height: "; cin>> l >> h; ... }
The comment in the template says the file is named with a .c extension, which makes it a C source file. But the code includes stuff that's only available in C++.

Is your assignment to write C or C++?

 10-15-2013, 06:52 AM PM User | #3 AceInfinity New Coder   Join Date: Jan 2013 Location: Canada Posts: 20 Thanks: 0 Thanked 0 Times in 0 Posts Looks like C++ code to me, taken from the ideas of a source file from C. If this was C, you would be able to use tricks with printf() and memset: Code: ```#include #include #include int main() { int height = 15; int width = 30; char sym = '#'; char layer[width+1]; memset (layer, sym, width+1); printf("%s\n", layer); for (int i = 0; i < height; i++) { printf ("%c%*c \n", sym, width, sym); } printf("%s\n", layer); return 0; }``` With C++, I would use a string and make use of the constructor that allows you to allocate a char of a certain repetition to be set, and just some string manipulation and loops. Code: ```std::string s(25, '*'); // Output 25 *'s: ************************* std::cout << s << std::endl;``` __________________ Microsoft MVP .NET Programming - (2012 - Present) ®Crestron DMC-T Certified Automation Programmer & Software Developer Last edited by AceInfinity; 10-15-2013 at 06:57 AM..

 Bookmarks

 Thread Tools Rate This Thread Rate This Thread: 5 : Excellent 4 : Good 3 : Average 2 : Bad 1 : Terrible

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home :: Client side development     JavaScript programming         DOM and JSON scripting         Ajax and Design         JavaScript frameworks         Post a JavaScript     HTML & CSS     XML     Flash & ActionScript         Adobe Flex     Graphics and Multimedia discussions     General web building         Site reviews         Building for mobile devices :: Server side development     Apache configuration     Perl/ CGI     PHP         Post a PHP snippet     MySQL         Other Databases     Ruby & Ruby On Rails     ASP     ASP.NET     Java and JSP     Other server side languages/ issues         ColdFusion         Python :: Computing & Sciences     Computer Programming     Computer/PC discussions     Geek News and Humour Web Projects and Services Marketplace     Web Projects         Small projects (quick fixes and changes)         Medium projects (new script, new features, etc)         Large Projects (new web application, complex features etc)         Unknown sized projects (request quote)         Vacant job positions         Looking for work/ for hire         Project collaboration/ partnership         Paid work offers and requests (Now CLOSED)     Career, job, and business ideas or advice     Domains, Sites, and Designs for sale         Domains for sale         Websites for sale         Design templates and graphics for sale :: Other forums     Member Offers     Forum feedback and announcements

All times are GMT +1. The time now is 07:23 PM.