63 217
Assignments Done
99,3%
Successfully Done
In July 2018

Answer to Question #47103 in C++ for Eunsu Kim

Question #47103
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.
Expert's answer
#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;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions