PDA

View Full Version : Just Code



Noxious020189
03-08-2006, 07:40 AM
I'm going to be entring a noob contest for high school students, and I just started C++ as some people know from my past threads. Anyways I have no way of transfering my data (code) from one place to another, so I thought that I could use this, and maybe get comments on as I go. It's due the 14 of this month so it won't be that long, but I still want to see if anyone would mind giving me little hints and help a begginer in programming out.


//PROGRAMMER NAME: Christopher Kaliszewski
//PROGRAM NAME: Geometric Calculator
//DATE STARTED: March 08, 2006
//DATE FINNISHED: TBA
//PURPOSE: Calculate and display all formulas of geometric calculations.

#include<iostream>
#include<iomanip.h>
int main()
{
//Main Menu
int Main_Menu_Selection;

cout <<"You can choose one option with a numeral:\n\n";
cout <<"1) Perimeter Calculations\n";
cout <<"2) Area Calculations\n";
cout <<"3) Volume Calculations\n";
cout <<"4) About Program\n";
cout <<"5) Exit\n\n";
cout <<"Where in the program would you like to go? ";
cin >>Main_Menu_Selection;

//Main Menu Error Finder
}

^I know it's just in the begging stages, but the "//Main Menu Error Finder" will be with a bool that allows the computer if they have not entered a number 1 -5 and will give them an error, so it dosen't error out the program.

Something Sexy
03-08-2006, 09:18 AM
Need some std:: in there dont you? Could toss in using namespace std; but I think that is bad programming practice.

Heretic
03-08-2006, 11:18 AM
Yes, you do need some std:: in there. You may also want to use #include<iomanip> instead of #include<iomanip.h>. The former is the C++ Standard Library header file, which supposedly ensures that your code will compile on most modern compilers (or some such nonsense...I could google why they changed from the old style ".h" includes to the new style, but I'm lazy).

Also, I find that gmail is an excellent place to store my code.

Noxious020189
03-08-2006, 11:59 AM
I know I honestly forgot the std, but not the iomanip :)

Axylone
03-08-2006, 03:44 PM
Is this competition just for your highschool? hehe

Heretic
03-08-2006, 04:33 PM
I know I honestly forgot the std, but not the iomanip :)

It's not that you forgot the iomanip include, it's that the old-style includes (those of the form #include<someHeaderName.h>) have been deprecated.

Noxious020189
03-08-2006, 06:03 PM
Is this competition just for your highschool? hehe

Its for colleges, but my teacher knows the judges so they offered it out to my calss, I know I'm going to get owned by them, but I want to put it into the ring

Anyways I did some more at home, and it's bed time for me so:


//PROGRAMMER NAME: Christopher Kaliszewski
//PROGRAM NAME: Geometric Calculator
//DATE STARTED: March 08, 2006
//DATE FINNISHED: TBA
//PURPOSE: Calculate and display all formulas of geometric calculations.

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//Main Menu - Where the program the begins.
MAIN_MENU:

int Main_Menu_Selection;

cout <<"You can choose one option with a numeral:\n\n";
cout <<"1) Perimeter Calculations\n";
cout <<"2) Area Calculations\n";
cout <<"3) Volume Calculations\n";
cout <<"4) Extra Calculations\n";
cout <<"5) About Program\n";
cout <<"6) Exit\n\n";
cout <<"Where in the program would you like to go? ";
cin >>Main_Menu_Selection;

//Main Menu Error Finder - Where the program finds out if they have put an invalid entry.
bool Main_Menu_Checker;

Main_Menu_Checker = Main_Menu_Selection >= 1 && Main_Menu_Selection <= 6;

if (Main_Menu_Checker == true)
{
system("cls");
goto MAIN_MENU_SORTING;
}
if (Main_Menu_Checker == false)
{
system("cls");
cout <<"YOU HAVE MADE AN INVALID ENTRY, PLEASE TRY AGAIN\n\n";
goto MAIN_MENU;
}

//Main Menu Sorting - Where the program directs the user by there choice.
MAIN_MENU_SORTING:

if (Main_Menu_Selection == 1)
{
system("cls");
goto PERIMETER_CALCULATIONS;
}
if (Main_Menu_Selection == 2)
{
system("cls");
goto AREA_CALCULATIONS
}

PERIMETER_CALCULATIONS:
AREA_CALCULATIONS:
}

Something Sexy
03-08-2006, 07:07 PM
DO NOT USE GOTOs....EVER....you will get owned hardcore.....very very very bad programming habbit. Loops are your friends.

Noxious020189
03-08-2006, 07:08 PM
DO NOT USE GOTOs....EVER....you will get owned hardcore.....very very very bad programming habbit. Loops are your friends.

I couldn't figure them out...I will when I get perfected

Something Sexy
03-08-2006, 07:21 PM
If you need some help with loops I would be more than willing to help you out. Just ask.

Noxious020189
03-09-2006, 05:05 AM
If you need some help with loops I would be more than willing to help you out. Just ask.

Thanks for the offer, and I might take it. Right now I know what I'm doing, but when I finish I'm going to enforce it. Just like writting an essay:

1) Rough Draft
2) Re-Read
3) Improve
4) Hand in :)

Once I'm on the improve I'll probley ask, and like I said this has to be turned after the weekend, so I'm going to probley ask around Sunday.

More code:

//PROGRAMMER NAME: Christopher Kaliszewski
//PROGRAM NAME: Geometric Calculator
//DATE STARTED: March 08, 2006
//DATE FINNISHED: TBA
//PURPOSE: Calculate and display all formulas of geometric calculations.

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//Main Menu - Where the program the begins.
MAIN_MENU:

int Main_Menu_Selection;

cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Perimeter Calculations\n";
cout <<"2) Area Calculations\n";
cout <<"3) Volume Calculations\n";
cout <<"4) Extra Calculations\n";
cout <<"5) About Program\n";
cout <<"0) Exit\n\n";
cout <<"What calculation would you like to use? ";
cin >>Main_Menu_Selection;

//Main Menu Error Finder - Where the program finds out if they have put an invalid entry.
bool Main_Menu_Checker;

Main_Menu_Checker = Main_Menu_Selection >= 0 && Main_Menu_Selection <= 5;

if (Main_Menu_Checker == true)
{
system("cls");
goto MAIN_MENU_SORTING;
}
if (Main_Menu_Checker == false)
{
system("cls");
cout <<"YOU HAVE MADE AN INVALID ENTRY, PLEASE TRY AGAIN\n\n";
goto MAIN_MENU;
}

//Main Menu Sorting - Where the program directs the user by there choice.
MAIN_MENU_SORTING:

if (Main_Menu_Selection == 1)
{
system("cls");
goto PERIMETER_CALCULATIONS;
}
if (Main_Menu_Selection == 2)
{
system("cls");
}
if (Main_Menu_Selection == 4)
{
system("cls");
}
if (Main_Menu_Selection == 5)
{
system("cls");
}
if (Main_Menu_Selection == 6)
{
system("cls");
}

PERIMETER_CALCULATIONS:

int Perimeter_Menu_Selection;

cout <<"Main Menu > Perimeter Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Backs\n\n";
cout <<"What type of shape would you like to calculate the perimeter for? ";
cin >>Perimeter_Menu_Selection;

AREA_CALCULATIONS:

int Area_Calculations_Selection;

cout <<"Main Menu > Area Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Backs\n\n";
cout <<"What type of shape would you like to calculate the area for? ";
cin >>Area_Calculations_Selection;
}

Heretic
03-09-2006, 11:42 AM
Yes, goto = bad. Very bad.

Just a note, you can put the 'system("cls")' outside of your if statements since it's in all of them.

Noxious020189
03-09-2006, 11:55 AM
Yes, goto = bad. Very bad.

Just a note, you can put the 'system("cls")' outside of your if statements since it's in all of them.

I know about the goto = bad, and I know that I can do that system(cls), but I like my code to look symetrical :)

Me = OCD (Not extreme)

Something Sexy
03-09-2006, 01:31 PM
Another suggestion would be to make functions for each menu item.

Noxious020189
03-09-2006, 02:25 PM
Another suggestion would be to make functions for each menu item.

What do you mean?


//PROGRAMMER NAME: Christopher Kaliszewski
//PROGRAM NAME: Geometric Calculator
//DATE STARTED: March 08, 2006
//DATE FINNISHED: TBA
//PURPOSE: Calculate and display all formulas of geometric calculations.

#include<iostream>
#include<iomanip>
#include<time.h>
using namespace std;
int main()
{
//Main Menu
MAIN_MENU:

int Main_Menu_Selection;

cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Perimeter Calculations\n";
cout <<"2) Area Calculations\n";
cout <<"3) Volume Calculations\n";
cout <<"4) Extra Calculations\n";
cout <<"5) About Program\n";
cout <<"0) Exit\n\n";
cout <<"What calculation would you like to use? ";
cin >>Main_Menu_Selection;

//Main Menu Error Finder
bool Main_Menu_Checker;

Main_Menu_Checker = Main_Menu_Selection >= 0 && Main_Menu_Selection <= 5;

if (Main_Menu_Checker == true)
{
system("cls");
goto MAIN_MENU_SORTING;
}
if (Main_Menu_Checker == false)
{
system("cls");
cout <<"YOU HAVE MADE AN INVALID ENTRY, PLEASE TRY AGAIN\n\n";
goto MAIN_MENU;
}

//Main Menu Sorting
MAIN_MENU_SORTING:

if (Main_Menu_Selection == 1)
{
system("cls");
goto PERIMETER_CALCULATIONS;
}
if (Main_Menu_Selection == 2)
{
system("cls");
goto AREA_CALCULATIONS;
}
if (Main_Menu_Selection == 4)
{
system("cls");
goto VOLUME_CALCULATIONS;
}
if (Main_Menu_Selection == 5)
{
system("cls");
goto EXTRA_CALCULATIONS;
}
if (Main_Menu_Selection == 6)
{
system("cls");
}

//Perimeter Calculations Menu
PERIMETER_CALCULATIONS:

int Perimeter_Menu_Selection;

cout <<"Main Menu > Perimeter Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the perimeter for? ";
cin >>Perimeter_Menu_Selection;

//Perimeter Calculation Menu Error Finder
bool Perimeter_Menu_Checker;

Perimeter_Menu_Checker = Perimeter_Menu_Selection >= 0 && Perimeter_Menu_Selection <= 10;

if (Perimeter_Menu_Checker == true)
{
system("cls");
}
if (Perimeter_Menu_Checker == false)
{
system("cls");
cout <<"YOU HAVE MADE AN INVALID ENTRY, PLEASE TRY AGAIN\n\n";
goto PERIMETER_CALCULATIONS;
}

//Perimeter Calculation Menu Sorting
PERIMETER_MENU_SORTING:

if (Main_Menu_Selection == 0)
{
system("cls");
goto MAIN_MENU;
}
if (Main_Menu_Selection == 1)
{
system("cls");
goto AREA_CALCULATIONS;
}
if (Main_Menu_Selection == 3)
{
system("cls");
goto VOLUME_CALCULATIONS;
}
if (Main_Menu_Selection == 4)
{
system("cls");
goto EXTRA_CALCULATIONS;
}
if (Main_Menu_Selection == 5)
{
system("cls");
}
if (Main_Menu_Selection == 6)
{
system("cls");
}
if (Main_Menu_Selection == 7)
{
system("cls");
}
if (Main_Menu_Selection == 8)
{
system("cls");
}
if (Main_Menu_Selection == 9)
{
system("cls");
}
if (Main_Menu_Selection == 10)
{
system("cls");
}

AREA_CALCULATIONS:

int Area_Calculations_Selection;

cout <<"Main Menu > Area Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the area for? ";
cin >>Area_Calculations_Selection;

VOLUME_CALCULATIONS:

int Volume_Calculations_Selection;

cout <<"Main Menu > Volume Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Sphear\n";
cout <<"2) Cone\n";
cout <<"3) Pyramid\n";
cout <<"4) Cube\n";
cout <<"5) Cuboid\n";
cout <<"6) Cylinder\n";
cout <<"7) Pentagonal\n";
cout <<"8) Hexagonal\n";
cout <<"9) Octagonal\n";
cout <<"10) Nonagonal\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the volume for? ";
cin >>Volume_Calculations_Selection;

EXTRA_CALCULATIONS:

int Extra_Calculations_Selection;

cout <<"Main Menu > Extra Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Money Conversions\n";
cout <<"2) Time Conversions\n";
cout <<"3) Tempetaure Conversions\n";
cout <<"4) Measurment Conversions\n";
cout <<"5) Tax Calculator\n";
cout <<"0) Back\n\n";
cout <<"What type of conversions or calculator would you like to use? ";
cin >>Extra_Calculations_Selection;
}

These goto's are on my nerves...Time to start cleaning it up even know it's not done

What looping should I do? :( I have no idea how to start

Something Sexy
03-09-2006, 04:33 PM
Well actually I would set up functions for each menu call you have, then you can use a series of if statements or a switch statement. For example you can make a function called Area_Function. You have to make a header in the beginning of your program like this:




void Area_Calculation();

int main()
{

your stuff;

}

void Area_Calculation()
{

int Area_Calculations_Selection;

cout <<"Main Menu > Area Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the area for? ";
cin >>Area_Calculations_Selection;
}



This will allow you to call your function and you can have everything for the area calculation in one place. I made it void just because you seem to want to be able to calculate many different types of shapes in each menu, so this way when you call this function you can do ALL the area_calculation menu and stuff inside that function.

Noxious020189
03-09-2006, 07:30 PM
Wait, whats diffrent from there than mine except the voids?


//PROGRAMMER NAME: Christopher Kaliszewski
//PROGRAM NAME: Geometric Calculator
//DATE STARTED: March 08, 2006
//DATE FINNISHED: TBA
//PURPOSE: Calculate and display all formulas of geometric calculations.

#include<iostream>
#include<iomanip>
using namespace std;
int main()
{
//Main Menu
MAIN_MENU:

int Main_Menu_Selection;

cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Perimeter Calculations\n";
cout <<"2) Area Calculations\n";
cout <<"3) Volume Calculations\n";
cout <<"4) Extra Calculations\n";
cout <<"5) About Program\n";
cout <<"0) Exit\n\n";
cout <<"What calculation would you like to use? ";
cin >>Main_Menu_Selection;

//Main Menu Error Finder
bool Main_Menu_Checker;

Main_Menu_Checker = Main_Menu_Selection >= 0 && Main_Menu_Selection <= 5;

if (Main_Menu_Checker == true)
{
system("cls");
goto MAIN_MENU_SORTING;
}
if (Main_Menu_Checker == false)
{
system("cls");
cout <<"YOU HAVE MADE AN INVALID ENTRY, PLEASE TRY AGAIN\n\n";
goto MAIN_MENU;
}

//Main Menu Sorting
MAIN_MENU_SORTING:

if (Main_Menu_Selection == 1)
{
system("cls");
goto PERIMETER_CALCULATIONS;
}
if (Main_Menu_Selection == 2)
{
system("cls");
goto AREA_CALCULATIONS;
}
if (Main_Menu_Selection == 4)
{
system("cls");
goto VOLUME_CALCULATIONS;
}
if (Main_Menu_Selection == 5)
{
system("cls");
goto EXTRA_CALCULATIONS;
}
if (Main_Menu_Selection == 6)
{
system("cls");
}

//Perimeter Calculations Menu
PERIMETER_CALCULATIONS:

int Perimeter_Menu_Selection;

cout <<"Main Menu > Perimeter Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the perimeter for? ";
cin >>Perimeter_Menu_Selection;

//Perimeter Calculation Menu Error Finder
bool Perimeter_Menu_Checker;

Perimeter_Menu_Checker = Perimeter_Menu_Selection >= 0 && Perimeter_Menu_Selection <= 10;

if (Perimeter_Menu_Checker == true)
{
system("cls");
}
if (Perimeter_Menu_Checker == false)
{
system("cls");
cout <<"YOU HAVE MADE AN INVALID ENTRY, PLEASE TRY AGAIN\n\n";
goto PERIMETER_CALCULATIONS;
}

//Perimeter Calculation Menu Sorting
PERIMETER_MENU_SORTING:

if (Perimeter_Menu_Selection == 0)
{
system("cls");
goto MAIN_MENU;
}

if (Perimeter_Menu_Selection == 1)
{
double
system("cls");
cout <<"Main Menu > Perimeter Calculations > Circle\n\n";
cout <<"Formula: 2(Pi)r\n";
cout <<"What It Means:\n";
cout <<"Pi = 3.14159265\n";
cout <<"r = Radius\n";
cout <<"*NOTE* The radius is half of the diamiter.\n\n\n";
cout <<"What is the radius of your circle? ";
cin >>
}

if (Perimeter_Menu_Selection == 2)
{
system("cls");

}

if (Perimeter_Menu_Selection == 3)
{
system("cls");

}

if (Perimeter_Menu_Selection == 4)
{
system("cls");

}

if (Perimeter_Menu_Selection == 5)
{
system("cls");

}

if (Perimeter_Menu_Selection == 6)
{
system("cls");

}

if (Perimeter_Menu_Selection == 7)
{
system("cls");

}

if (Perimeter_Menu_Selection == 8)
{
system("cls");

}

if (Perimeter_Menu_Selection == 9)
{
system("cls");

}

if (Perimeter_Menu_Selection == 10)
{
system("cls");

}

AREA_CALCULATIONS:

int Area_Calculations_Selection;

cout <<"Main Menu > Area Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Circle\n";
cout <<"2) Triangle\n";
cout <<"3) Square\n";
cout <<"4) Rectangle\n";
cout <<"5) Pentagon\n";
cout <<"6) Hexagon\n";
cout <<"7) Heptagon\n";
cout <<"8) Octagon\n";
cout <<"9) Nonagon\n";
cout <<"10) Octagon\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the area for? ";
cin >>Area_Calculations_Selection;

VOLUME_CALCULATIONS:

int Volume_Calculations_Selection;

cout <<"Main Menu > Volume Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Sphear\n";
cout <<"2) Cone\n";
cout <<"3) Pyramid\n";
cout <<"4) Cube\n";
cout <<"5) Cuboid\n";
cout <<"6) Cylinder\n";
cout <<"7) Pentagonal\n";
cout <<"8) Hexagonal\n";
cout <<"9) Octagonal\n";
cout <<"10) Nonagonal\n";
cout <<"0) Back\n\n";
cout <<"What type of shape would you like to calculate the volume for? ";
cin >>Volume_Calculations_Selection;

EXTRA_CALCULATIONS:

int Extra_Calculations_Selection;

cout <<"Main Menu > Extra Calculations\n\n";
cout <<"You can choose one option with a numeral:\n\n\n";
cout <<"1) Money Conversions\n";
cout <<"2) Time Conversions\n";
cout <<"3) Tempetaure Conversions\n";
cout <<"4) Measurment Conversions\n";
cout <<"5) Tax Calculator\n";
cout <<"0) Back\n\n";
cout <<"What type of conversions or calculator would you like to use? ";
cin >>Extra_Calculations_Selection;
}
^For tommrow in school

Something Sexy
03-10-2006, 12:47 AM
In yours you are still using gotos, mine is split up into sperate functions.

Noxious020189
03-10-2006, 06:22 AM
In yours you are still using gotos, mine is split up into sperate functions.

Well ya, like I said I am cleaning it up when I have it all setup...I know I said was getting sick of them, but I hate to change my way in the middle, so when I'm done I willl