Answer the question
In order to leave comments, you need to log in
How to determine the smallest and largest value with two variables, as well as the sum, difference, etc.?
Hello .
Started learning C++.
I read the chapter - " Objects Types and Values ", from the book I'm learning from by Bjarne Stroustrup.
Task : Write a program that prompts the user to enter two integer values + the definition of the smallest and largest values, as well as the sum, difference, product and quotient of these values.
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int val1, val2;
cout << "Введите два целочисленных значения.\n";
cin >> val1, val2;
system("pause");
}
Answer the question
In order to leave comments, you need to log in
cin >> val1;
cin >> val2;
This line assigns the entered values.
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "Russian");
int val1, val2;
cout << "Введите два целочисленных значения.\n";
cin >> val1;
cin >> val2;
if (val1 > val2) { // - делаем условие для проверки (если 1 значение больше 2, то 1- максимальное, 2 - минимальное)
cout << "Большее " << val1 << endl
<< "Меньшее " << val2 << endl;
}
if (val1 < val2) {
cout << "Большее " << val2 << endl
<< "Меньшее " << val1<< endl;
}
else { // - если никакое из предыдущих условий не сработало, значит выводить что значения равны, так как другого не дано)
cout << "Значения равны" << endl;
}
}
int razn;
razn = val1-val2;
cout << "Разница = " << razn << endl;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question