Write a calculator program in c++ language
- User
Write a calculator program in c++ language
- Assistant
Sure! Here is a basic calculator program in C++ that performs addition, subtraction, multiplication, and division:
c++#include <iostream> using namespace std; int main() { double num1, num2; char operation; cout << "Enter first number: "; cin >> num1; cout << "Enter operation (+, -, *, /): "; cin >> operation; cout << "Enter second number: "; cin >> num2; switch (operation) { case '+': cout << "Result: " << num1 + num2 << endl; break; case '-': cout << "Result: " << num1 - num2 << endl; break; case '*': cout << "Result: " << num1 * num2 << endl; break; case '/': if (num2 != 0) { cout << "Result: " << num1 / num2 << endl; } else { cout << "Error: Division by zero is not allowed!" << endl; } break; default: cout << "Error: Invalid operation!" << endl; } return 0; } - User
Write a program that fulfills the following conditions In a movie theater, seats are often arranged with shifting adjacent rows for the convenience of the audience. Suppose in such a movie theater N seats in the 1st, 3rd, 5th and all odd rows and N + 1 seats in the 2nd, 4th and all even rows. even rows. The seats in the rows are numbered from 1 to N in odd rows and from 1 to N + 1 in even rows. rows. The box office sells tickets in a row: first in the 1st row for seats from 1 to N, then - in the 2nd row. for seats from 1st to N + 1, then to the 3rd row from the 1st seat, etc. Determine the row number and seat number for the Kth ticket sold. Input data format The program receives two integers as input. The first line contains the number N (1 6 N 6 109 ) - the number of seats in the 1st row of the theater. The second line contains the number K - is the serial number of the sold ticket (1 6 K 6 2 × 109 ). Output data format The program should output two numbers: the row number and the seat number of the K-th sold ticket.
- Assistant
To solve this problem, we can observe a pattern in the seating arrangement. In each row, there are N seats in odd rows and N + 1 seats in even rows. The total number of seats in each row is determined by the row number.
Here is a C++ program that calculates the row number and seat number for the K-th ticket sold:
cpp