fork download
  1. // Tutorial 1
  2. #include <iostream>
  3. #include <string>
  4.  
  5. int main()
  6. {
  7. char ch; // compile-time initialization
  8. ch = 't';
  9. std::cout <<"Char 'ch' has value "<< ch << '\n';
  10. std::string name;
  11. std::cout << "What is your name? ";
  12. getline (std::cin, name); // run-time initialization
  13. std::cout << "Hello, " << name << "!\n";
  14. bool truebool;
  15. truebool = true;
  16. bool falsebool = false;
  17. std::cout <<"Note true is "<< truebool <<" and false is " << falsebool <<'\n';
  18. bool boolean;
  19. std::cout <<"Enter a boolean value: ";
  20. std::cin >> boolean; // numbers in (-1,1) give 0, other numbers 1, else 0
  21. std::cout <<"Boolean is "<<boolean<<'\n';
  22. int a,b;
  23. double c;
  24. a = 4;
  25. b = a;
  26. std::cout <<"A is "<<a<<" and B is "<<b<<'\n';
  27. a = 6;
  28. std::cout <<"A is "<<a<<" and B is "<<b<<'\n';
  29. c = 9.5;
  30. a = c;
  31. std::cout <<"A is "<<a<<" and B is "<<b<<" and C is "<<c<<'\n';
  32. c = 10.9;
  33. b = c;
  34. std::cout <<"A is "<<a<<" and B is "<<b<<" and C is "<<c<<'\n';
  35. c = a;
  36. std::cout <<"A is "<<a<<" and B is "<<b<<" and C is "<<c<<'\n';
  37. return 0;
  38. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
Char 'ch' has value t
What is your name? Hello, !
Note true is 1 and false is 0
Enter a boolean value: Boolean is 0
A is 4 and B is 4
A is 6 and B is 4
A is 9 and B is 4 and C is 9.5
A is 9 and B is 10 and C is 10.9
A is 9 and B is 10 and C is 9