Hi guys can you help me with my calculator? I want to give loop to my codes using do while loop. Is it possible? and add "Q" for Quit/Exit. Here are my codes: Can you give me an I dea?
Following code compiles fine with Dev C++ (mingw) #include <stdio.h> #include <conio.h> //for getch #include <cstdlib> //for system int main() { float left, right, answer; float sum,difference,product,qoutient; char oper; char ch=0; while(1) { system("cls"); printf("Q) Quit / Exit\nAny other key to make calculation\n\n"); ch = getch(); if(ch=='q' || ch=='Q') break; printf("\n\n enter new expression: "); scanf("%f %c %f", &left, &oper, &right); sum = left + right; difference = left - right; product = left * right; qoutient = left / right; if (oper == '+') printf("\n Answer: %f ",sum); else if (oper == '-') printf("\n Anser: %f",difference); else if (oper == '*') printf("\n Answer: %f",product); else if (oper == '/') printf("\n Answer: %f",qoutient); else printf("\n Invalid operator!"); printf("\n\nPress Return to continue..."); getch(); } return 0; } Code (markup): regards