Log in

View Full Version : [Help pls] Is this a good layout (c++)



Oleh
16-09-2011, 12:22 AM
I'm currently learning basic level c++ in college (Just started).

I'm wondering, is this a good layout?


#include<iostream>
#include<conio.h>

using namespace std;

void main(void)

{
float radius, height, volume, surfacearea, sumone, sumtwo;
cout<<"Please enter Radius ";
cin>>radius;
cout<<"Please enter Height ";
cin>>height;
volume=3.142*radius*radius*height;
sumone=2*3.142*radius*radius;
sumtwo=2*3.142*radius*height;
surfacearea=sumone+sumtwo;
cout<<"Volume "<<volume<<endl;
cout<<"Surface Area "<<surfacearea<<endl;
getch();
}


Or would it be better to just leave everything as is?

Edited by Catzsy (Forum Super Moderator): Thread moved from 'Technology Discussion ' to here as probably more suitable

HotelUser
16-09-2011, 02:45 AM
Do you mean layout in terms of ease to read, or layout in terms of maximizing the efficiency of your program? If the latter it's fine from my perspective, if the foremost your layout looks fine, abit messy in spots:



#include<iostream>
#include<conio.h>

using namespace std;

void main(void)
{
//declare variables
float radius, height, volume, surfacearea, sumone, sumtwo;

//collect user input
cout << "Please enter Radius ";
cin >> radius;
cout << "Please enter Height ";
cin >> height;

//preform mathematical calculations
volume = 3.142 * radius * radius * height;
sumone =2 * 3.142 * radius * radius;
sumtwo =2 * 3.142 * radius * height;
surfacearea = sumone + sumtwo;

//display results and keep application running
cout << "Volume " << volume << endl;
cout << "Surface Area " << surfacearea << endl;
getch();
}

LordUsagi
17-09-2011, 02:20 AM
Comments will make every ones world a better place and I'm sure your teacher would appreciate it too. Just a few words describing what you are doing in the following section usually does the trick.

Then again, if you're in college hopefully they teach you how to format / present your code.

Want to hide these adverts? Register an account for free!