Welcome Guest
Established

Bat may void po? Nested if else lang daw gagamitin namin... Hindi ba siya possible ma code using nested if else lang?eto naman flowchart
View attachment 716620
#include <iostream>
#ifdef _WIN32
#define CLEAR "cls"
#elif __linux__
#define CLEAR "clear"
#endif
int main(void) {
int operation, num1a, num1b, num2a, num2b;
std::string menu { "\nOPERATIONS\n----------\n 1) Addition\n 2) Subtraction\n 3) Multiplication\n 4) Division\nEnter operation: " };
std::cout << menu;
std::cin >> operation ;
while (operation < 1 || operation > 4) {
system(CLEAR);
std::cout << "\nINVALID INPUT. PLEASE RE-ENTER\n------------------------------\n" << std::endl;
std::cout << menu;
std::cin >> operation;
}
if (operation == 1) {
int sum, num1a, num1b, num2a, num2b;
float quotient1, quotient2;
// FIRST FRACTION SET
std::cout << "\nPerforming Addition\n-------------------\n\nFIRST FRACTION SET" << std::endl;
std::cout << "Enter num1: ";
std::cin >> num1a;
std::cout << "Enter num2: ";
std::cin >> num2a;
while (num2a == 0) {
std::cout << "\nERROR! DIVISION BY ZERO!" << std::endl;
std::cout << "Please re-enter num2: ";
std::cin >> num2a;
}
quotient1 = (float) num1a / (float) num2a;
// SECOND FRACTION SET
std::cout << "\nSECOND FRACTION SET" << std::endl;
std::cout << "Enter num1: ";
std::cin >> num1b;
std::cout << "Enter num2: ";
std::cin >> num2b;
while (num2b == 0) {
std::cout << "\nERROR! DIVISION BY ZERO!" << std::endl;
std::cout << "Please re-enter num2: ";
std::cin >> num2b;
}
quotient2 = (float) num1b / (float) num2b;
std::cout << "\nThe SUM of " << num1a << "/" << num2a << " and " << num1b << "/" << num2b << " is " << quotient1+quotient2 << "\n" << std::endl;
}
return 0;
}
Thanks po dito sir... But i can't use your code kasi wala pa kami sa void and mga while loop or loops. Pero magagamit ko din to later on. Salamat po sa codes thank you sa effor aydol.For a starter, using only (nested) ifs is quite a silly idea because you will end up with if-blocks longer than a train. Regardless, to satisfy the requirements, here's my silly code. (ADDITION is the only one implemented. I'll let you do the rest.)
C++:#include <iostream> #ifdef _WIN32 #define CLEAR "cls" #elif __linux__ #define CLEAR "clear" #endif int main(void) { int operation, num1a, num1b, num2a, num2b; std::string menu { "\nOPERATIONS\n----------\n 1) Addition\n 2) Subtraction\n 3) Multiplication\n 4) Division\nEnter operation: " }; std::cout << menu; std::cin >> operation ; while (operation < 1 || operation > 4) { system(CLEAR); std::cout << "\nINVALID INPUT. PLEASE RE-ENTER\n------------------------------\n" << std::endl; std::cout << menu; std::cin >> operation; } if (operation == 1) { int sum, num1a, num1b, num2a, num2b; float quotient1, quotient2; // FIRST FRACTION SET std::cout << "\nPerforming Addition\n-------------------\n\nFIRST FRACTION SET" << std::endl; std::cout << "Enter num1: "; std::cin >> num1a; std::cout << "Enter num2: "; std::cin >> num2a; while (num2a == 0) { std::cout << "\nERROR! DIVISION BY ZERO!" << std::endl; std::cout << "Please re-enter num2: "; std::cin >> num2a; } quotient1 = (float) num1a / (float) num2a; // SECOND FRACTION SET std::cout << "\nSECOND FRACTION SET" << std::endl; std::cout << "Enter num1: "; std::cin >> num1b; std::cout << "Enter num2: "; std::cin >> num2b; while (num2b == 0) { std::cout << "\nERROR! DIVISION BY ZERO!" << std::endl; std::cout << "Please re-enter num2: "; std::cin >> num2b; } quotient2 = (float) num1b / (float) num2b; std::cout << "\nThe SUM of " << num1a << "/" << num2a << " and " << num1b << "/" << num2b << " is " << quotient1+quotient2 << "\n" << std::endl; } return 0; }