Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

Projects so far continued.

Thanks for viewing part 2!

Project: Calculator
Info: First real project, the comments where for something unrelated.
Created for: Main Project at Camp, Practicing Beginner Things...

Code
#include <iostream>
#include <string.h>
#include <math.h>
#include <cstdlib>
using namespace std;
char intructions[60]; //Variable to decide if user wants instructions
char pastinst[60];  //Decides if they still want to use the calc after viewing the instructions
int num1; //First nubmer user entered to be used in math operation
int num2; //Send number, used the same as above ^
char action[60]; //What the user wants to do with the two numbers above
char X[60]; //Useless variable, I think I used to test arrays.
char redo[60]; //Variable used to when I was working on restarting calc after doing a opperation, can be deleted.
char exitprogram[60]; //Used in same situation as above, but used to exit teh program
int pivalue = 3.1415926535; //The definition of PI I used for one of the actions in the calc
char qexit[60] = "c"; //variable used to begin operation of calc, or to quit after using calc
int main() {
    system("color 8f"); //I'm evil for using system(), but I used this to polish it up, changes CMD Prompt color.
    while (strcmp( qexit, "c") == 0){
        system("cls"); //used when the calc restarts at end to clear the cmd window
        cout << "\t\t\t  |\\N35QU1K's Quick Calc/|"; //Ascii art, once again polishing.
        cout << "\n\t\t\t   __";
        cout << "\n\t\t\t   |  __  |";
        cout << "\n\t\t\t   | | N35QU1K     0. | |";
        cout << "\n\t\t\t   | |__| |";
        cout << "\n\t\t\t   |   ___ ___ ___  ___    |";
        cout << "\n\t\t\t   |  | 7 | 8 | 9 |   | + |   |";
        cout << "\n\t\t\t   |  |___|___|___|   |___|   |";
        cout << "\n\t\t\t   |  | 4 | 5 | 6 |   | - |   |";
        cout << "\n\t\t\t   |  |___|___|___|   |___|   |";
        cout << "\n\t\t\t   |  | 1 | 2 | 3 |   | x |   |";
        cout << "\n\t\t\t   |  |___|___|___|   |___|   |";
        cout << "\n\t\t\t   |  | . | 0 | = |   | / |   |";
        cout << "\n\t\t\t   |  |___|___|___|   |___|   |";
        cout << "\n\t\t\t   |__|";
        cout << "\n\n__";
        cout << "\n~~";
        cout << "__";
        cout << "\n\n\t\t  Press \"c\" now to continue (Or anything else to quit)"; // Decides if user wants to continue, mainly for after restarts
        cout << "\n\t\t\t\t  Enter choice: "; // Prompt user for user input
        cin >> qexit; //User input for qexit Aswers above question and assigns a certain value to qexit
        if (strcmp( qexit, "c") != 0){
            exit(1);// if qexit not equal to "c" then close the program
        }
        system("cls"); //clears the program window
        cout << "\t\t\t\t  Coded in C++"; //First big project coded in C++ =D
        cout << "\n--";
        cout << "  Do you want instructions for the use of this Calculator? (Yes or No) ";
        cout << "\t\t\t\t  Enter choice (Yes or No): ";
        cin >> intructions; //assigns value to variable instructions
        system("cls"); //clears program window
        cout << "\n\n\n\t\t\t\t  _"; //ASCII art of some nesquik!
        cout << "\n\t\t\t\t  \\";
        cout << "\n\t\t\t\t  ==";
        cout << "\n\t\t\t\t  /..\\";
        cout << "\n\t\t\t\t    |~~~~|";
        cout << "\n\t\t\t\t    |~~~~|";
        cout << "\n\t\t\t\t    N35QU1K";
        //Change to string compare below
  //Above is notes
        if (strcmp( intructions, "Yes" ) == 0){
            cout <<  "\n\t\t\t\t||Instructions||"; //above compared a variable to a string and this is outputting instructions for user.
            cout << "\n\n\tThis is used as just a common calculator, enter in your numbers, chose\nyour calculation you will want,";
            cout << " for example I would chose type 152, then X for multiplaying, then 4 as my last number. The last number can be empty for example,";
            cout << "when you would do sqaure roots you do this, 1. 25 2. $ 3. <blank> and you would get 5.";
            cout << "As simple as that!\n\n";
            cout << "Do you want to continue? (Yes or No.) ";
            cin >> pastinst; //decides if user wants to continue using calc
            system("cls"); //clears program window
        }
        if (strcmp( pastinst, "No" ) == 0){
            exit(1); //closes program if variable pastinst is not equal to the string "No"
            }

        cout << "\nAvailable actions are: \nmultiplying = X \ndivision = / \naddition = +\nsubtraction = - \nopposites = %"; // Tells user avaible actions
        cout << " \nPowers = ^ \nSquare root = $ \nAbsolute Value = # \nFind the Area of Circle and Circumfrence = @"; //same as above

        cout << "\n\nAction: ";
        cin >> action; //assigns value to instruction
        if(strcmp( action, "%") == 0 || strcmp( action, "$") == 0 || strcmp( action, "#") == 0 || strcmp( action,"@") == 0){
            if(strcmp( action, "%") == 0){
                cout << "\nNumber to become opposite: "; // I used the above to decide which if statements would be used in a certain circumstance
                cin >> num1; // Continued from above, so that it makes more sense than it asking fro a second number when it only needs one
                cout << num1 << " " << action << " is = " << num1/-1; //carries out the action they wanted and prints it out
            }
            if(strcmp( action, "$") == 0){
                cout << "\nFind the square root of: ";
                cin >> num1;
                cout << num1 << " " << action << " is = " << sqrt((float)num1);//carries out the action they wanted and prints it out

            }
            if(strcmp( action, "#") == 0){
                cout << "\nAbsoulute value of: ";
                cin >> num1;
                cout << num1 << " " << action << " is = " << fabs((float)num1);//carries out the action they wanted and prints it out
            }
            if(strcmp( action, "@") == 0){
                cout << "\nRadius: ";
                cin >> num1;
                cout << "\n" << "A circle with a radius of " << num1 << " has these attributes: " << "\n" << "It has a area of: " << pivalue*num1*num1 << "\nAnd a circumfrence of: " << num1*pivalue;
            } //carries out the action they wanted and prints it out ^
        }else{
            cout << "\n\nNumber 1: "; // these are in the else because they need 2 numbers to carrie out teh action
    cin >> num1;
    cout << "\nNumber 2: ";
    cin >> num2;
    if (strcmp( action, "X" ) == 0){
                cout << num1 << " " << action << " " << num2 << " is = " << num1*num2;        //carries out the action they wanted and prints it out    
            }
    if (strcmp( action, "/") == 0){
                cout << num1 << " " << action << " " << num2 << " is = " << num1/num2;//carries out the action they wanted and prints it out
            }
    if (strcmp( action, "+") == 0){
                cout << num1 << " " << action << " " << num2 << " is = " << num1+num2;//carries out the action they wanted and prints it out
            }
    if (strcmp( action, "-") == 0){
                cout << num1 << " " << action << " " << num2 << " is = " << num1-num2;//carries out the action they wanted and prints it out
            }
    if (strcmp( action, "^") == 0){
                cout << num1 << " " << action << " " << num2 << " is = " << pow ((float)num1, (float)num2);//carries out the action they wanted and prints it out
            }

        }
        cout << "\n\n"; //new lines
        system("pause"); //Once again evil sytstem, but I started doing more multi platform friendly commands in later projects, look at game of life
// btw it just propmts user to press the enter/return key

        system("cls"); // clear program screen
        cout << "      \\-._,, /\"/"; //ascii art of a giraffe with a twisted kneck
        cout << "\n     \\\"-/  l-'";
        cout << "\n     \\  /\\";
        cout << "\n     | /\\  \\";
        cout << "\n    (_/  \\  %----.__";
        cout << "\n    \\/ ___    \\";
        cout << "\n    ,'  /   '-.__|_";
        cout << "\n    |   \\'-.___    \\";
        cout << "\n     \\__ '/   _/\\_  '-.";
        cout << "\n     \\/   /-.  \\_   \\";
        cout << "\n    /   |   \\_  \\   |";
        cout << "\n     /   / \\_   '-'   /";
        cout << "\n    |    |   '-.___,-'";
        cout << "\n    ,-'  |";
        cout << "\n     /  \"-._";
        cout << "\n     |     '-._";
        cout << "\n    \\    \\";
        cout << "\n    | \\     |-.";
        cout << "\n    \\  | /'-._,-|    /   \\";
        cout << "\n     | \\ |  \\    |    $";
        cout << "\n     \\ | /  |  /";
        cout << "\n    | /  \\ |";
        cout << "\n    |/     |/";
        cout << "\nThanks for trying my program! My first thing coded in C++ So get this Girraffe."; //Thanks the user.
        cout << "\n";
        system("pause"); //pause system to ask them to contiue
    }
    system("cls"); //clears the screen again, using evil system() Then the program loops from the first while()
}

That's it so far, if you have any answers to previous things, or you know what I should try next as a project, please reply!
Nice man, you should try making it into a user friendly ui using QT Creator !
(Aug 25, 2011 01:53 AM)Turmoil Wrote:  Nice man, you should try making it into a user friendly ui using QT Creator !
I would but I can't find any guides. Please link me.
Awesome calc ;] Try making gui now, im sure u'll enjoy it
i would suggest Gtk+ over QT
but again gtk comez VERY bad without a good IDE (probably their creator isnt very good :S)
but it lookz good in both windows and Gnome
(Aug 25, 2011 09:18 AM)Manzzup Wrote:  i would suggest Gtk+ over QT
but again gtk comez VERY bad without a good IDE (probably their creator isnt very good :S)
but it lookz good in both windows and Gnome

Yeah, I would love for my programs to be cross platform, but right now I can't find any guides for creatings GUIs for either QT or GTK, you got any ideas?
(Aug 25, 2011 05:27 PM)zenawenliang Wrote:  Yeah, I would love for my programs to be cross platform, but right now I can't find any guides for creatings GUIs for either QT or GTK, you got any ideas?

i dont recommend GTK.
It's a biatch (sometimes).
[Image: KtaBQWs.png]
(Aug 25, 2011 06:32 PM)eKKiM Wrote:  i dont recommend GTK.
It's a biatch (sometimes).

God damn it, either way is there any guides?
(Aug 25, 2011 06:39 PM)zenawenliang Wrote:  God damn it, either way is there any guides?

I don't know you Cpp skills but this should get you started i think:
http://sector.ynet.sk/qt4-tutorial/
[Image: KtaBQWs.png]
(Aug 25, 2011 06:39 PM)zenawenliang Wrote:  God damn it, either way is there any guides?
I'm sure you meant, "are* there any guides?"
Spoiler (Click to View)
And to answer your question, this is for GTK (warning, it's C):
http://developer.gnome.org/gtk-tutorial/2.90/
(Aug 25, 2011 06:43 PM)eKKiM Wrote:  I don't know you Cpp skills but this should get you started i think:
http://sector.ynet.sk/qt4-tutorial/

Thanks, looking for more of these, and I am past pointers, getting past classes, done with functions, and all that junk.
EDIT: Looked through the tutorial, I don't think this is the GUI Version of QT I'm looking for...
Isnt anyone just a little bit perturbed that he used center tags on code because the thought it might be "cool". It isnt "cool"... it looks like shit and I will continually use this example (until its changed) as a reason to hate humanity and want to murder small children and puppies.
(Aug 25, 2011 06:46 PM)stdio Wrote:  Isnt anyone just a little bit perturbed that he used center tags on code because the thought it might be "cool". It isnt "cool"... it looks like shit and I will continually use this example (until its changed) as a reason to hate humanity and want to murder small children and puppies.

Shit, sorry bro, I didn't look it over, I was just mass editing, I'll fix it right now bro.
EDIT: Fixed it! Sorry stdio, you're one of my favorite members of the coding section, didn't want to piss you off.
(Aug 25, 2011 07:02 PM)zenawenliang Wrote:  Shit, sorry bro, I didn't look it over, I was just mass editing, I'll fix it right now bro.
EDIT: Fixed it! Sorry stdio, you're one of my favorite members of the coding section, didn't want to piss you off.

You've restored my faith in humanity for the time being! Thanks, despite HF enjoying to mess with code formatting because of the x3 rule (three tabs, three letters, three spaces, etc) to hopefully reduce spam it still looks way easier to read.
(Aug 25, 2011 07:18 PM)stdio Wrote:  You've restored my faith in humanity for the time being! Thanks, despite HF enjoying to mess with code formatting because of the x3 rule (three tabs, three letters, three spaces, etc) to hopefully reduce spam it still looks way easier to read.
Thanks but I am still looking for Updated QT Guides for C++


Possibly Related Threads...
Thread / Author Replies Views Last Post
[.NET] by ~AcidSep 29, 2012 03:37 PM 1 70 Sep 29, 2012 03:37 PM
Last Post: Pussy Cat
[.NET] by Coding4NoobsDec 17, 2011 02:58 PM 21 719 Dec 17, 2011 02:58 PM
Last Post: Coding4Noobs
[.NET] by Mr. AndersonSep 27, 2010 12:51 PM 32 339 Sep 27, 2010 12:51 PM
Last Post: Mr. Anderson