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”
main() { int a, b, c; printf(“Enter the number ‘x’: “); scanf(“%d”, &a); b = a * 3; c=a+b; printf(“%d, %d * 3 =% d, %d +% d =% d”, a, a, b, a, b, c); getch(); }
using namespace std; int main() { setlocale(LC_ALL, “Russian”); int a, b, c; cout << "Введите а: " <> a; b = a + 3; c = a + b; cout << "b равна: " << b << " " << "c равна: " << c << endl; system("pause"); return 0;
it happens …
Second)) Working
#include
main()
{
int a, b, c;
printf(“Enter the number ‘x’: “);
scanf(“%d”, &a);
b = a * 3; c=a+b;
printf(“%d, %d * 3 =% d, %d +% d =% d”, a, a, b, a, b, c);
getch();
}
#include
using namespace std;
int main(){
setlocale(LC_ALL, “rus”);
double Chokolat;
double maslo;
single text;
double x,Y,from,sum;
double cena_chokolat = 0;
double cena_maslo = 0;
double cena_testo = 0;
cout <> x;
cout <> Y;
cout <> from;
cout <> cena_chokolat;
cout <> cena_maslo;
cout <> cena_testo;
Chokolat = x * cena_chokolat;
maslo = y * cena_maslo;
text = z * cena_testo;
cout << "\a\a\a\a\a\a" << endl;
cout << " \Chocolate t left in the amount of = " << Chokolat << " rub " <<endl;
cout << " \t the oil remains in the amount of = " << maslo << " rub " << endl;
cout << " \t Test for the amount remaining = " << text << " rub " << endl;
sum = Chokolat + maslo + text;
cout << " \t The sum of all goods = " << sum << " rub " << endl;
return 0;
}
thanks
2 задача короче сделал, зачем длинные слова?)
количество шоколада??
и как это понимать русскому человеку?)
Скорее всего плиток шоколада. И вообще зря придираешься.
Почему я не могу посмотреть код?
#include
#include
using namespace std;
int main()
{
setlocale(LC_ALL, “Russian”);
int a, b, c;
cout << "Введите а: " <> a;
b = a + 3;
c = a + b;
cout << "b равна: " << b << " " << "c равна: " << c << endl;
system("pause");
return 0;
}