Aug 24, 2011 07:57 PM
(This post was last modified: Aug 25, 2011 07:03 PM by zenawenliang.)
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...
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!



![[Image: KtaBQWs.png]](https://i.imgur.com/KtaBQWs.png)