Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write a calculator program using a do-while loop in c++ 2011
#1
Code:
#include <iostream> #include <string> using namespace std; int result; char sign; int value; int main() { result = 0; // Loop forever (or till we hit the break statement) do { cout << "Current value is " << result << '\n'; cout << "Please enter an operation +, -, *, / <'Q' to quit>: "; cin >> sign; cout << "Please enter a number: "; cin >> value; if (sign != '+' && sign != '-' && sign != '*' && sign != '/') { cout << "Unknown operator " << sign << '\n'; } else { if (sign = '+') { result += value; } else { if (sign = '-') { result -= value; } else { if (sign = '*') { result *= value; } else { if (sign = '/') { result /= value; } } } } } } while (1); return (0); }

0300-9520262
Get solution in 24 hour
|cpmputer & internetConfusedmileys81:[SIZE="4"][SIZE="3"]....[/SIZE][/SIZE]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  c++ program on unix varup 0 7,580 10-10-2012, 06:16 PM
Last Post: varup
  i take input from getchar(); function in program in C++ 2012 Vuhelper 0 2,992 05-31-2012, 01:40 AM
Last Post: Vuhelper
  program Output in C++ 2012 Vuhelper 0 2,957 01-06-2012, 12:28 AM
Last Post: Vuhelper
  For running C++ program from command prompt “gcc” and “g++” compilers are used. Vuhelper 0 6,391 01-04-2012, 10:41 PM
Last Post: Vuhelper
  Why we write main rgc,char**argv in C++ 2012 Vuhelper 0 3,022 01-04-2012, 10:36 PM
Last Post: Vuhelper
  how can we write the postfix expression of 3 + 5 * 6 – 7 * (8 + 5)? Vuhelper 0 5,447 01-04-2012, 10:16 PM
Last Post: Vuhelper
  array project code c++ 2011 Vuhelper 0 1,273 12-10-2011, 06:32 PM
Last Post: Vuhelper
  factorial in C++ code 2011 Vuhelper 0 943 12-10-2011, 06:31 PM
Last Post: Vuhelper
  stack during function call in C++ 2011 Vuhelper 0 2,026 11-05-2011, 05:05 PM
Last Post: Vuhelper
  Function (Retrun push)for what purpose use in the program. ? Vuhelper 0 1,861 11-05-2011, 05:03 PM
Last Post: Vuhelper

Forum Jump:


Users browsing this thread: 1 Guest(s)