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 main() { setlocale(LC_ALL, “rus”); int a,b,c; int sum; cout<<"Введите стоимость шоколадки="<>a; cout<<"Стоимость шоколадки="<<a<<endl; cout<<"Введите стоимость кофе="<>b; cout<<"Стоимость кофе="<<b<<endl; cout<<"Введите стоимость молока="<>c; cout<<"Стоимость молока="<<c<<endl; sum=a+b+c; cout<<"Общая стоимость покупки="<<sum<<endl; }
//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.
#include”pch.h”
#include
using namespace std;
void main()
{
setlocale(LC_ALL, “ru”);
int milk, choc, coffe;
float milkP, chocP, coffeP;
cout << "Введите кол-во пакетов молока и цену " <> milk >> milkP;
cout << "Введите кол-во плиток шоколада и цену" <> choc >> chocP;
cout << "Введите кол-во стиков кофе и цену" <> coffe >> coffeP;
cout << "Молоко " << milk << " X " << milkP << " = " << milk * milkP << endl
<< "Шоколад " << choc << " X " << chocP << " = " << choc * chocP << endl
<< "Кофе " << coffe << " X " << coffeP << " = " << coffe * coffeP << endl
<< "Итого " << milk * milkP + choc * chocP + coffe * coffeP;
cout << endl << endl << endl;
}
#include”pch.h”
#include
using namespace std;
//void main()
//{
// setlocale(LC_ALL, “ru”);
// int milk, choc, coffe;
// float milkP, chocP, coffeP;
// cout << "Введите кол-во пакетов молока и цену " <> milk >> milkP;
// cout << "Введите кол-во плиток шоколада и цену" <> choc >> chocP;
// cout << "Введите кол-во стиков кофе и цену" <> coffe >> coffeP;
// cout << "Молоко " << milk << " X " << milkP << " = " << milk * milkP << endl
// << "Шоколад " << choc << " X " << chocP << " = " << choc * chocP << endl
// << "Кофе " << coffe << " X " << coffeP << " = " << coffe * coffeP << endl
// << "Итого " << milk * milkP + choc * chocP + coffe * coffeP;
//
//
// cout << endl << endl << endl;
//}
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “rus”);
int a,b,c;
int sum;
cout<<"Введите стоимость шоколадки="<>a;
cout<<"Стоимость шоколадки="<<a<<endl;
cout<<"Введите стоимость кофе="<>b;
cout<<"Стоимость кофе="<<b<<endl;
cout<<"Введите стоимость молока="<>c;
cout<<"Стоимость молока="<<c<<endl;
sum=a+b+c;
cout<<"Общая стоимость покупки="<<sum<<endl;
}
1.
#include
using namespace std;
int main() { // number of goods
setlocale (0,”russian”);
int = choco 5;
int coffe = 2;
int milk = 2;
float onEchcko = 89.5;
float onEcoffe = 192.68;
float onEmilk = 34.90;
float sym = (choco * onEchcko) + (coffe * onEcoffe) + (milk * onEmilk);
std::cout << "общая сумма покупки – " << sym << endl;
return 0;
}
#include “pch.h”
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Rus”);
int a, b, c;
cout <> a;
cout << endl;
b = a + 3;
c = a + b;
cout << "Вторая переменная равна " << b;
cout << endl;
cout << "Третья переменная равна " << c;
cout << endl;
}
//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.
And this site is powerfully me Comments…
int a, b, c, d;
cout <> a;
cout << endl;
b = a;
c = a;
d = a * 3;
cout << "Количество предметов на столе: " << d;
cout << endl;
}
//Declare variables, to count the total number of objects for the table. for example cups, the same number of saucers and spoons.
#include “pch.h”
#include
using namespace std;
void shop() {
float milk = 40.1, chocolate = 89.5, coffee = 198.89;
int value;
cout <> value;
milk *= value;
cout <> value;
chocolate *= value;
cout <> value;
coffee *= value;
cout << "Покупка будет стоить вам: " << milk + chocolate + coffee << " pybley" <> a;
b = a + 3;
c = a + b;
cout << a << b << c;
}
void servTable() {
int a, b, c;
cout <> a;
c = b = a;
cout << "Кол-во чашек: " << a << "\nКол-во ложек: " << b << "\nКол-во блюдец: " << c << endl;
}
int main()
{
setlocale(LC_ALL, "rus");
shop();
variebls();
servTable();
}