The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 9:25 am



 [ 25 posts ]  Go to page 1, 2  Next
G0L3M's Code - Update, menu and conversions! 
Author Message
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
IPO #1 - This took me a single day to make =p its for simple conversions and is actually quite useful(if you don't like entering the equations on a calculator)
Code:
#include <stdlib.h>
#include <iostream.h>
#include <iomanip.h>
#include "devconfx.h"
const double pi = 3.14, ft = 3.2808399, in = 39.3700787, fr = .555555555555, ce = 1.8;

void wait()
{
   gotoxy(25,24);
   cout << "Press any key to continue..." << flush;
   _getch();
}

void circles()
{
    double d1, d2, d3, d4, d5;
   clrscr();
   gotoxy(17,1);
   cout << "Radius to circumfrence, diameter and area.";
   gotoxy(17,3);
   cout <<"Input the radius of your circle here: ";
   cin >> d1;
   d2 = 2 * d1;
   gotoxy(17,4);
   cout << "The diameter of your circle is: " << d2;
   gotoxy(17,5);
   d3 = 2 * pi * d1;
   cout << "The circumfrence of your circle is: " << d3;
   gotoxy(15,6);
   d4 = pi * d1;
   d5 = d4 * d4;
   cout << "The area of your circle is: " << d5;
   wait();
}

void metricConversion()
{
    double d1, d2, d3;
   clrscr();
   gotoxy(17,1);
   cout << "This is metric conversion.";
   gotoxy(17,3);
   cout << "Enter your length in Meters: ";
   cin >> d1;
   gotoxy(17,4);
   d2 = d1 * ft;
   cout << "Your length in feet: " << d2;
   gotoxy(17,5);
   d3 = d1 * in;
   cout << "Your length in inches: " << d3;
   wait();
}

void fToCconversion()
{
    double d1, d2, d3;
   clrscr();
   gotoxy(17,1);
   cout << "This is Fahrenheit to Celsius conversion." << endl;
   gotoxy(17,3);
   cout << "Enter your degrees in Fahrenheit: ";
   cin >> d1;
   gotoxy(17,4);
   d2 = d1 - 32;
   d3 = d2 * fr;
   cout << "Your value in Celsius: " << d3;
   wait();
}

void cToFconversion()
{
    double d1, d2, d3;
   clrscr();
   gotoxy(17,1);
   cout << "This is Celsius to Fahrenheit conversion." << endl;
   gotoxy(17,3);
   cout << "Enter your degrees in Celsius: ";
   cin >> d1;
   gotoxy(17,4);
   d2 = d1 * ce;
   d3 = d2 + 32;
   cout << "Your value in Fahrenheit: " << d3;
   wait();
}

char menu()
{
   char ch;
   clrscr();
   gotoxy(15,3);
   cout <<"Your choices are:"<< endl;

   gotoxy(25,5);
   cout <<"1 - Radius to circumfrence & area of the circle."<< endl;
   gotoxy(25,6);
   cout <<"2 - Metric Conversion."<< endl;
   gotoxy(25,7);
   cout <<"3 - Fahrenheit to Celsius conversion"<< endl;
   gotoxy(25,8);
   cout <<"4 - Celsius to Fahrenheit conversion."<< endl;
   gotoxy(25,9);
   cout <<"Q - Closes program or brings you back to the menu."<< endl;
   
   ch = toupper(getch());
   return ch;
}

void process(char ch)
{
   if (ch == '1')
      circles();
   else if (ch == '2')
      metricConversion();
   else if (ch == '3')
      fToCconversion();
   else if (ch == '4')
      cToFconversion();
}

int main()
{
   char ch;
   initscreen();
   settitlebar("IPO1 - Nick Acton");
   textcolor(fgBlack);
   textbackground(bgWhite);
   clrscr();
   ch = menu();
   while (ch != 'Q')
   {
      process(ch);
      ch = menu();
   }
   uninitscreen();
   return 0;
}

It's not commented yet and I don't think ill upload the commented version unless requested to do so. Either way I decided to use constants instead of entering huge decimals in the code, I think it turned out quite well.

_________________
Image


Last edited by Nick on Thu Oct 27, 2011 3:49 pm, edited 5 times in total.



Thu Sep 29, 2011 3:48 pm
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
You misspelled Begin but it looks fine to me.

_________________
Image


Thu Sep 29, 2011 11:51 pm
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
SS wrote:
You misspelled Begin but it looks fine to me.

=p I should fix that at school tomorrow, and I will probably upload other programs in this topic as well.

_________________
Image


Fri Sep 30, 2011 12:13 am
User avatar

Joined: Tue Jun 16, 2009 2:48 am
Posts: 834
Location: Australia.
Gender: Male
Skype: snoble7
its ok


Fri Sep 30, 2011 3:26 am

Joined: Sat Apr 16, 2011 7:39 pm
Posts: 1451
Location: Enjoying Life
Country: United States (us)
Gender: Male
Skype: sazhchocobo
Currently Playing: League of Legends, Killing Floor 2, Overwatch
Waifu: Cleod9
is this C++?

_________________
Trying my best to better myself as a programmer! Please visit my programming blog, any and all tips are welcome!: https://conceptsexplained.wordpress.com


Fri Sep 30, 2011 3:25 pm
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
sazh wrote:
is this C++?

Yep, and WB.

_________________
Image


Fri Sep 30, 2011 4:12 pm
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
Update in the original post.

_________________
Image


Tue Oct 04, 2011 3:10 pm
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
Ha, cool.
You could've made it cleaner by putting the calculations part in different tabs or whatever they're called, and basically made the main page nothing but function calls.

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Tue Oct 04, 2011 7:49 pm
WWW
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Okay for starting out, but no doubt you'll make those calculations their own functions soon enough.

_________________
Image


Wed Oct 05, 2011 3:39 am
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
You could also put reading the variables as its own function.
Like I said earlier, you can basically make main() nothing but calls to other functions. Bit of extra work, but much cleaner, and for more complex projects, it becomes easier to add in new features when it's organized like that.

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Wed Oct 05, 2011 4:25 am
WWW
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
Thanks for the advice guys, I wont be cleaning up this code but I'll be taking this advice to my newer projects.

_________________
Image


Wed Oct 05, 2011 9:15 am
User avatar

Joined: Tue Apr 06, 2010 4:47 am
Posts: 2081
Location: At home, working and playing
Gender: Male
Woah.. This looks amazing... Nice job dude :D
Small question since my teacher didn't teach me this on the first day :<
Is "Cin" supposed to be like an inputbox?


Wed Oct 05, 2011 3:03 pm
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
Michael M wrote:
Woah.. This looks amazing... Nice job dude :D
Small question since my teacher didn't teach me this on the first day :<
Is "Cin" supposed to be like an inputbox?

I guess you could call it that =p
I believe you can also use this
VARIABLE_1 = getch()
The VARIABLE_1 is a representation of any variable you set =p someone can correct me if I'm wrong.

_________________
Image


Wed Oct 05, 2011 3:06 pm
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
cin means console input. It allows a line in the command prompt where the user can input a value (so it could be a number or a symbol or a sentence or whatever).

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Wed Oct 05, 2011 9:24 pm
WWW
User avatar

Joined: Fri Sep 17, 2010 12:31 am
Posts: 2229
Gender: N/A
Update in the original post, also working on a menu for a couple simple functions. I should have it done by monday (if not then I don't know when).

_________________
Image


Tue Oct 25, 2011 3:56 pm
Display posts from previous:  Sort by  
 [ 25 posts ]  Go to page 1, 2  Next

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.