#include <iostream> #include <stdlib.h> using namespace std; int main(int argc, char *argv[]) { cout << "Simple Calculator By: Michael Hedden (The_kid)\n\n"; cout << "Enter \"5\" to quit"; double type; double restart; double fnumber; double snumber; double answer; line20: cout << "\n\n\n\nWhat type of Math would you like to do? (+[1], -[2], x[3], or ö[4]) "; cin >> type; if (type==1) { cout << "\n\n\aPlease input 2 numbers separated by a space, and I shall add them: "; cin >> fnumber; cin >> snumber; answer = fnumber + snumber; cout << "\n\nThe correct answer is: " << answer << "\n\n\n"; } if (type==2) { cout << "\n\n\aPlease input 2 numbers separated by a space, and I shall subtract them: "; cin >> fnumber; cin >> snumber; answer = fnumber - snumber; cout << "\n\nThe correct answer is: " << answer << "\n\n\n"; } if (type==3) { cout << "\n\n\aPlease input 2 numbers separated by a space, and I shall multiply them: "; cin >> fnumber; cin >> snumber; answer = fnumber * snumber; cout << "\n\nThe correct answer is: " << answer << "\n\n\n"; } if (type==4) { cout << "\n\n\aPlease input 2 numbers separated by a space, and I shall divide them: "; cin >> fnumber; cin >> snumber; answer = fnumber / snumber; cout << "\n\nThe correct answer is: " << answer << "\n\n\n"; } if (type==5) { return 0; } if (type>=6) { INTerror: cout << "\n\nI'm sorry, but you have incountered an unexpected error, please try again."; cout << "\n\nWould you like to try again? (yes[1] or no[2]) "; cin >> restart; if (restart==1){ goto line20;} if (restart==2){ return 0;} if (restart>=3){ goto INTerror;} } goto line20; system("pause"); return 0; }
My calculator
Started by the_kid, Feb 12 2004 05:54 AM
2 replies to this topic
#1
Posted 12 February 2004 - 05:54 AM
well here it is... I find good use for it.
#2
Posted 11 December 2024 - 01:52 PM
Here is my calculator code for days calculations from a certain date :
#include <iostream> #include <string> #include <sstream> #include <ctime> using namespace std; // Function to check if a year is a leap year bool isLeapYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return true; } return false; } // Function to get the number of days in a month int daysInMonth(int month, int year) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: // 31 days return 31; case 4: case 6: case 9: case 11: // 30 days return 30; case 2: // February (28 or 29 days) return isLeapYear(year) ? 29 : 28; default: return 0; } } // Function to calculate the difference in days between two dates int calculateDays(int day1, int month1, int year1, int day2, int month2, int year2) { struct tm a = {0}, b = {0}; a.tm_year = year1 - 1900; a.tm_mon = month1 - 1; a.tm_mday = day1; b.tm_year = year2 - 1900; b.tm_mon = month2 - 1; b.tm_mday = day2; time_t x = mktime(&a); time_t y = mktime(&b); // Return the absolute difference in days return abs(difftime(y, x) / (60 * 60 * 24)); } int main() { int day1, month1, year1, day2, month2, year2; cout << "Enter the first date (YYYY MM DD): "; cin >> year1 >> month1 >> day1; cout << "Enter the second date (YYYY MM DD): "; cin >> year2 >> month2 >> day2; // Calculate the difference in days int daysDifference = calculateDays(day1, month1, year1, day2, month2, year2); cout << "The number of days between the two dates is: " << daysDifference << " days." << endl; return 0; }
#3
Posted 22 December 2024 - 02:39 AM
Here is my calculator code for days calculations from a certain date :
#include <iostream> #include <string> #include <sstream> #include <ctime> using namespace std; // Function to check if a year is a leap year bool isLeapYear(int year) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return true; } return false; } // Function to get the number of days in a month int daysInMonth(int month, int year) { switch (month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: // 31 days return 31; case 4: case 6: case 9: case 11: // 30 days return 30; case 2: // February (28 or 29 days) return isLeapYear(year) ? 29 : 28; default: return 0; } } // Function to calculate the difference in days between two dates int calculateDays(int day1, int month1, int year1, int day2, int month2, int year2) { struct tm a = {0}, b = {0}; a.tm_year = year1 - 1900; a.tm_mon = month1 - 1; a.tm_mday = day1; b.tm_year = year2 - 1900; b.tm_mon = month2 - 1; b.tm_mday = day2; time_t x = mktime(&a); time_t y = mktime(&b); // Return the absolute difference in days return abs(difftime(y, x) / (60 * 60 * 24)); } int main() { int day1, month1, year1, day2, month2, year2; cout << "Enter the first date (YYYY MM DD): "; cin >> year1 >> month1 >> day1; cout << "Enter the second date (YYYY MM DD): "; cin >> year2 >> month2 >> day2; // Calculate the difference in days int daysDifference = calculateDays(day1, month1, year1, day2, month2, year2); cout << "The number of days between the two dates is: " << daysDifference << " days." << endl; return 0; }Just find out this site calculatro site calculadoradediasfechasanos.com for days calculator but their code is in different language.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users