1. Write a program that consists of a while-loop that (each time around the loop) reads two ints and then prints them. Exit the program when a terminating '|' is entered.
2. change the program to write out "the smaller value is:" followed by the smaller of the numbers and "the larger value is:" followed by the larger value.
1
Expert's answer
2014-09-29T14:18:40-0400
#include <iostream> #include <cstdlib> using namespace std; inline int max(int a, int b) { return a > b ? a : b; } inline int min(int a, int b) { return a < b ? a : b; } int main() { char firstValue[32], secondValue[32]; // default buffers for input while (true) { cin >> firstValue; if (firstValue[0] == '|') { cout << "terminate input" << endl; break; } cin >> secondValue; if (isdigit(firstValue[0]) && isdigit(secondValue[0])) { int firstInt = atoi(firstValue); int secondInt = atoi(secondValue); cout << "values: " << firstInt << ", " << secondInt << endl; cout << "Max value:" << max(firstInt, secondInt) << endl; cout << "Min value:" << min(firstInt, secondInt) << endl; } else { cout << "Enter integer numbers" << endl; } } return 0; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment