Here are collected the task to the article Data types, variables and constants. Try to solve problems on their own and only need to look at the decision. So you will learn much faster programming fundamentals.
1. Declare variables with which you can calculate the total amount of the purchase of several products. For example a chocolate bar, coffee and packets of milk.
View 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
#include <iostream>
usingnamespacestd;
intmain()
{
setlocale(LC_ALL,"rus");
intchocolate=2;// хранит количество упаковок
intmilk=3;
intcoffee=1;
floatpriceOfChocolate=11.04;// хранит цены за одну упаковку
2. Declare three variables of type int, and the first to assign a numeric value, the second variable is the first variable increased by 3, and the third variable is equal to the sum of the first two.
View code
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
usingnamespacestd;
intmain()
{
intfirst=4;
intsecond=first+3;
intthird=first+second;
cout<<"first = "<<first<<endl;
cout<<"second = "<<second<<endl;
cout<<"third = "<<third<<endl;
return0;
}
3. Declare variables, to count the total number of objects for the table. for example cups, the same number of saucers and spoons.
View code
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
usingnamespacestd;
intmain()
{
setlocale(LC_ALL,"rus");
intcups=6;// количество чашек
intspoons=cups;// количество ложек равно кол-тву чашек
intsaucers=cups;// блюдца
// или можно так записать
// int cups, spoons, saucers;
// cups = spoons = saucers = 6;
intamount=cups+spoons+saucers;// общее количество
cout<<"Всего "<<amount<<" предметов"<<endl;
return0;
}
4.7
155
126 thoughts on “Tasks: Data types, variables and constants”
int d; cout << "введите количество гостей: " <> d; int a = d; //cup int b = d; //saucer int c = d; //spoons int g = a + b + c; cout << "Нужно чашек: " << a << endl<<"Нужно ложек: " << c << endl<<"нужно блюдец: " << d << endl<<"всего предметов= " << g << endl;
I ignored COUT (online compiler)
#include
using namespace std;
int chocoP, milkP, cofeP, chocoC, milkC, cofeC;
int main() {
setlocale(LC_ALL, “rus”);
cout << "Вводите количество шоколадок" <> chocoC;
cout << "Введите цену шоколадок" <> chocop;
cout << "Вводите количество молока" <> milkC;
cout << "Введите цену молока" <> milkP;
cout << "Вводите количество кофе" <> cofeC;
cout << "Введите цену кофе" <> cofeP;
cout << "Сумма шоколадок" << chocoC * chocop << endl;
cout << "Cумма молока" << milkC*milkP << endl;
cout << "Cумма кофе" << cofeC*cofeP << endl;
cout << "ИТОГО " << chocoC * chocop cofeC + * + cofeP milkC * milkP << endl;
return 0;
}
#include
The first line should be #include
Otherwise cout will not work
cout << "Вводите количество шоколадок" chocoC;
cout << "Вводите количество молока" milkC;
cout << "Введите цену молока" milkP;
cout << "Вводите количество кофе" cofeC;
cout << "Введите цену кофе" cofeP
2 стрелочки в разные стороны
second problem was solved by another sympathetic, and then the question is brewing.
I did everything right tk. It gives the correct answer.
#include
using namespace std;
int main()
{
int nm_1 = 11;
int nm_2 = 0;
int nm_3 = 0;
nm_2 = (nm_1 + 3);
nm_3 = (nm_1 + nm_2);
cout << nm_3<<endl;
return 0;
}
It gives the correct answer (25)
Why are so many code, here at 2 line vlozhidsya:
int a = 5, b = a*3, c = a + b;
cout<<a<<"\n"<<b<<"\n"<<c;
int d;
cout << "введите количество гостей: " <> d;
int a = d; //cup
int b = d; //saucer
int c = d; //spoons
int g = a + b + c;
cout << "Нужно чашек: " << a
<< endl<<"Нужно ложек: " << c
<< endl<<"нужно блюдец: " << d
<< endl<<"всего предметов= " << g << endl;
#include
using namespace std;
int main()
{
cout << "\t\t\t\tПродукти\t\t"<< endl;
float a = 3.5;
float b = 2.7;
float c = 4.8;
float ad = 0.9855;
float bd = 0.99;
cout << "\tЦіна Продуктів: " << " Milk = 3.5 $ t Meat = 2.7 $ t $ 4.8 Chocolate =" <<endl;
int aNumber;
int bNumber;
int cNumber;
cout <> aNumber;
cout <> bNumber;
cout <> cNumber;
float sum1 = ( a * aNumber );
float sum2 = ( b * bNumber );
float sum3 = ( c * cNumber );
float PriceOfProducts = ( sum1 * ad ) + ( sum2 * bd ) + sum3;
float PriceOfMilk = sum1 * ad;
float PriceOfMeat = sum2 * bd;
cout << " Price of Milk: " << sum1 << "$" << "\t\tЗа знижкою:" << PriceOfMilk << "$" <<endl;
cout << " Price of meat: " << sum2 << "$" << "\t\tЗа знижкою:" << PriceOfMeat << "$" << endl;
cout << " chocolate Price: " << sum3 << "$" << "\tЗнижка відсутня" << endl;
cout <” << endl;
cout << "\t\tЦіна Продуктів: = " << PriceOfProducts << "$" << endl << endl;;
return 0;
}
№1-Completed*
#include
using namespace std;
int main()
{
int first, second, third;
cin >> first;
second = first + 3;
third = first + second;
cout << "second = " << second << "\n third = " << third;
return 0;
}
№2- Completed
#include
using namespace std;
int main()
{
int cups, soucer, spoons;
cin >> cups;
soucer = spoons = cups;
cout << "soucer = " << soucer << "\n\t spoons = " << spoons;
return 0;
}
№3-Completed
I like this happened
setlocale(LC_ALL, “russian”);
int chokolat, coffee, moloko;
cout <> Chokolat;
cout <> coffee;
cout <> moloko;
int price = chokolat + coffee + moloko;
cout << "Общая цена всех продуктов" << price <<"\n";
The first made pokrasivshe
#include “pch.h”
#include
using namespace std;
int main()
{
setlocale(0, “”);
int chocolate;
int milk;
int coffee;
cout <> chocolate;
cout <> milk;
cout <> coffee;
float priceOfChocolate = 11.04;
float priceOfMilk = 9.59;
float priceOfCoffee = 70.77;
float sum = 0;
sum = (chocolate * priceOfChocolate) + (milk * priceOfMilk) + (coffee * priceOfCoffee);
cout << "Общая стоимость покупки = " << sum << endl;
return 0;
}