In a previous articleData output on the screen and in theentray data from the keyboardWe examined in detail this topic. It's time to practice – because we have a lot of work, to develop certain skills, needed a programmer and develop their logical thinking quietly.
1. Create 4 variables with different types of data and ask the user to enter values in them. After entering the, display them on the screen.
Show code
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>
usingnamespacestd;
intmain()
{
setlocale(LC_ALL,"rus");
intdigit=0;
doubledigit2=0;
charsymbol=0;
booltrueOrFalse=0;
cout<<"Введите целое число: ";
cin>>digit;
cout<<"Введите вещественное число: ";
cin>>digit2;
cout<<"Введите символ: ";
cin>>symbol;
// в переменную типа bool с помощью cin можно ввести
// только числа 0 (интерпретируется как false) и 1 (true)
cout<<"Введите 0 или 1: ";
cin>>trueOrFalse;
cout<<endl<<endl;
cout<<"Целое число: "<<digit<<endl;
cout<<"Вещественное число: "<<digit2<<endl;
cout<<"Символ: "<<symbol<<endl;
cout<<"bool: "<<trueOrFalse<<endl;
return0;
}
Result:
2. Create 5 variables of type char, ask the user to enter a word of five letters, and show these symbols (the word) the screen. (Enter characters in Latin, tk. cyrillic is displayed incorrectly. Why? This will be discussed in one of our next lessons)
In future, we will learn how to work with strings with you and we will not have to keep the words in different variables and display them on the screen spell.
3. Display the text in this form:
4. The user must enter 2 numbers. You need to show on the screen the product of these numbers, sum and difference. Show the same arithmetic mean of these numbers entered.
what's the problem with using string, well, or getline(), if there are spaces in the line? And so it turns out that after each character you need to enter a space
cout << "\a\a\a\a\a\n"; cout << " Why doesn't she ever like it in a restaurant?,\n"; cout << " She ordered that the, and always like it, what did I order?\n"; cout << " And she begins to eat from my plate. I tell her:\n"; cout << " \"Закажи себе то же самое\". Она говорит \"Зачем? \n"; cout << " Я только попробовать\". И съедает половину.\n"; cout << " //k.f.. \"О чём говорят мужчины\"//\n";
int digit = 0; double digit2 = 0; char symbol = 0; bool trueOrFalse = 0;
cout <> digit; cout <> digit2; cout <> symbol; // в переменную типа bool с помощью cin можно ввести // только числа 0 (интерпретируется как false) and 1 (true) cout <> trueOrFalse;
return 0; } What am I doing wrong ?? The very first data entry works for me and then it just crashes, and I can't enter anything else. Whoever saw my mistake, please respond to my comment
#include ;
using namespace std;
crayon-620a9ebe8fb50629382471/()
{
setlocale(LC_ALL, “ru”);
char a, b, c, d, e;
cout << "Введите буквы по порядку" <> a >> b >> c >> d >> e;
cout << "Ваше слово – " << a << b << c << d << e;
return 0;
}
what's the problem with using string, well, or getline(), if there are spaces in the line? And so it turns out that after each character you need to enter a space
crayon-620a9ebe8fb50629382471/
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
cout << "\a\a\a\a\a\n";
cout << " Why doesn't she ever like it in a restaurant?,\n";
cout << " She ordered that the, and always like it, what did I order?\n";
cout << " And she begins to eat from my plate. I tell her:\n";
cout << " \"Закажи себе то же самое\". Она говорит \"Зачем? \n";
cout << " Я только попробовать\". И съедает половину.\n";
cout << " //k.f.. \"О чём говорят мужчины\"//\n";
return 0;
}
int main()
{
setlocale(LC_ALL, “rus”);
int digit = 0;
double digit2 = 0;
char symbol = 0;
bool trueOrFalse = 0;
cout <> digit;
cout <> digit2;
cout <> symbol;
// в переменную типа bool с помощью cin можно ввести
// только числа 0 (интерпретируется как false) and 1 (true)
cout <> trueOrFalse;
cout << endl << endl;
cout << "Целое число: " << digit << endl;
cout << "Вещественное число: " << digit2 << endl;
cout << "Символ: " << symbol << endl;
cout << "bool: " << trueOrFalse << endl;
return 0;
}
What am I doing wrong ?? The very first data entry works for me and then it just crashes, and I can't enter anything else. Whoever saw my mistake, please respond to my comment
int main()
{
int ferstName;
float youAge;
double likeYou;
cout <> ferstName;
cout <> youAge;
cout <> likeYou;
cout << endl << endl;
cout << "Your Ferst Name:" << ferstName << endl;
cout << "Your old age:" << youAge << endl;
cout << "thing becouse your like:" << likeYou << endl;
return 0;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
int a;
char b;
float c;
double d;
cout <> a;
cout <> b;
cout <> c;
cout <> d;
cout << "\nВсе типы данных которые вы ввели по очерености: " << a << ", " << b << ", " << c << ", " << d;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
char a, b, c, d, i;
cout <> a >> b >> c >> d >> i;
cout << "\nУ вас получилось слово: " << a << b << c << d << i << "\n";
cout << "Ваша первая буква: " << a;
cout << "\nВаша вторая буква: " << b;
cout << "\nВаша третья буква: " << c;
cout << "\nВаша четвертая буква: " << d;
cout << "\nВаша пятая буква: " << i;
}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
float a, b, composition ,sum, difference, mean, d;
cout <> a;
cout <> b;
composition = a * b;
sum = a + b;
difference = a – b;
mean = (a + b) / 2;
cout << "Произведение двух чисел: " << composition;
cout << "\nСумма двух чисел: " << sum;
cout << "\nРазница двух чисел: " << difference;
cout << "\nCреднее арифметическое двух чисел: " << mean;
}
A question, why float does not return a fractional number, last task.
(6+5)/2=5…
indicate variables with a dot, like a fraction.
(6.0 + 5.0)/2.0 …