. (*), , .
Fahrenheit = (Celsius * 1.8) + 32
. Windows Calculator! , . :
✓ ;
✓ .
. , convert.. .
#include <iostream>
using namespace std;
int main() {
//
double ctemp, ftemp;
//
cout << "Input a Celsius temp and press ENTER: ";
cin >> ctemp;
// ftemp (Fahrenheit)
ftemp = (ctemp * 1.8) + 32;
cout << "Fahrenheit temp is: " << ftemp;
return 0;
}
, , C++ , (//). C++ ( ), .
3: , .
4: , : ftemp ( ), ctemp ( ). . (: - ctemp = (ftemp - 32) /1.8.)
if if-else
- , ». , i f C++. if:
if ()
if, , . (, , .)
if ( == )
cout << " and are equal.";
. (==) (=). . C++ : , ; .
, , ? (compound statement) ( (statement block)):
|
|
if ( == )
{
cout << " and are equal." endl;
cout "Isn't that nice?";
they_are__equal = true;
}
, , . ( , ) , - , (}).
({}) , . if, :
, C++ , .
, , . . , else.
if {}
1
else
2
4: ?
, . , , (%) if-else .
, , , . , if.
#include <iostream>
using namespace std;
int main()
{
int n, remainder;
cout << "Enter a number and press ENTER: ";
cin >> n;
// 2
remainder = n % 2;
// 0, ,
if (remainder == 0)
cout << "The number is even.";
else
cout << "The number is odd.";
return 0;
}
n, remainder.
n 2 . (modulus) (remainder). , ( ) remainder ( ).
remainder = n % 2;
(%) C++ . :
3 %2 1 Odd ()
4 % 2 0 Even ()
25% 2 1 Odd
60% 2 0 Even
25 % 5 0 Divisible by 5 ( 5)
13 % 5 3 Not divisible by 5 (He 5)
5: ( ).
6: .