#include <iostream>
int main() {
std::cout << "hello world!";
}
hello world!
#include <iostream>
int main() {
std::cout << "Hello there,";
std::cout << "General Kenobi!";
}
Hello there,General Kenobi!
#include <iostream>
int main() {
std::cout << "Hello there,";
std::cout << "\n";
std::cout << "General Kenobi!";
}
Hello there,
General Kenobi!
#include <iostream>
int main() {
std::cout << "Hello there,";
// endl = end of line
std::cout << std::endl;
std::cout << "General Kenobi!";
}
Hello there,
General Kenobi!
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout << "Hello there,";
cout << endl;
cout << "General Kenobi!";
}
Hello there,
General Kenobi!
#include <iostream>
using std::cout;
using std::endl;
int main() {
cout << "Hello there," << endl << "General Kenobi!";
}
Hello there,
General Kenobi!
Task 1
Create a new method with body from main.#include <iostream>
using std::cout;
using std::endl;
void hello() {
cout << "Hello there," << endl
<< "General Kenobi!";
}
int main() {
hello();
}
Hello there,
General Kenobi!
#include <iostream>
using std::cout;
using std::endl;
namespace helpers {
void hello() {
cout << "Hello there," << endl
<< "General Kenobi!";
}
}
int main() {
helpers::hello();
}
Hello there,
General Kenobi!
What could go wrong if we swap namespace and main?
Task 2
Write a program, that takes params for equation: ax2+bx+c=0,#include <iostream>
using std::cout;
using std::cin;
int main() {
int number;
cout << "Type a number: ";
cin >> number;
cout << "Your number is: " << number;
}
Type a number: 42
Your number is: 42
#include <iostream>
using std::cout;
using std::cin;
namespace my_math {
int sum(int a, int b) {
return a + b;
}
}
int main() {
int x, y;
cin >> x >> y;
int sum = my_math::sum(x, y);
if (sum > 100) {
cout << "sum is greater than 100";
}
}
50 140
sum is greater than 100
Task 3
Create a BMI calculator.