cout << "How
many nickels do you have? ";
int nickels;
cin >> nickels;
cout << "How
many dimes do you have? ";
int dimes;
cin >> dimes;
cout << "How
many quarters do you have? ";
int quarters;
cin >> quarters;
double total = pennies
* 0.01 + nickels * 0.05 +
dimes * 0.10 + quarters * 0.25;
/* total value
of the coins */
cout << "Total
value = " << total << "\n";
return 0;
}
How many pennies do you
have? 10
How many nickels do you have? 3 How many dimes do you have? 7 How many quarters do you have? 3 Total value = 1.70 |
10 3 7 3 |
10 3 7
3 |
Оператор за присвояване
#include <iostream>
using namespace std;
int main()
{ cout << "How
many pennies do you have? ";
int count;
cin >> count;
double total = count
* 0.01;
cout << "How
many nickels do you have? ";
cin >> count;
total = count * 0.05
+ total;
cout << "How
many dimes do you have? ";
cin >> count;
total = count * 0.10
+ total;
cout << "How
many quarters do you have? ";
cin >> count;
total = count * 0.25
+ total;
cout << "Total
value = " << total << "\n";
return 0;
}
* текуща стойност на променлива
* дефиниция на променлива (единствена
!)
-- с инициализация
double total = count * 0.01;
-- без инициализация
int
count;
* оператор за присвояване
total = count * 0.05 + total;
* знакът за равенство в математиката
и в С++
* съкращение за оператора добавяне
на 1 и изваждане на 1
month=month+1
month++
month=month-1
month--