centralized performance resources
This commit is contained in:
commit
50b15a1522
63 changed files with 328466 additions and 0 deletions
38
perf-cpp/scripts/ch4.cc
Normal file
38
perf-cpp/scripts/ch4.cc
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
Write the following program: The user is asked to enter 2 floating point numbers (use doubles). The user is then asked to enter one of the following mathematical symbols: +, -, *, or /. The program computes the answer on the two numbers the user entered and prints the results. If the user enters an invalid symbol, the program should print nothing.
|
||||
*/
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
double x, y;
|
||||
std::cout << "enter x: "<<'\n';
|
||||
std::cin >> x;
|
||||
std::cout << "enter x: "<<'\n';
|
||||
std::cin >> y;
|
||||
std::cout << "enter symbol " << '\n';;
|
||||
char symbol;
|
||||
std::cin >> symbol;
|
||||
|
||||
double ans;
|
||||
switch (symbol) {
|
||||
case '+':
|
||||
ans = x + y;
|
||||
break;
|
||||
case '-':
|
||||
ans = x - y;
|
||||
break;
|
||||
case '*':
|
||||
ans = x * y;
|
||||
break;
|
||||
case '/':
|
||||
ans = x / y;
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
std::cout << "answer: " << ans << '\n';
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue