When your done your program should look something like this. make sure you understand what you are typing don't just mindlessly copy, you wont learn anything from that.
#include <iostream> using namespace std; int main() { cout << "Counting forward:\n"; for (int i = 0; i < 10; ++i) { cout << i << " "; } cout << "\n\nCounting backward:\n"; for (int i = 9; i >= 0; --i) { cout << i << " "; } cout << "\n\nCounting by fives:\n"; for (int i = 0; i <= 50; i += 5) { cout << i << " "; } cout << "\n\nCounting with null statements:\n"; int count = 0; for ( ; count < 10; ) { cout << count << " "; ++count; } cout << "\n\nCounting with nested for loops:\n"; const int ROWS = 5; const int COLUMNS = 3; for (int i = 0; i < ROWS; ++i) { for (int j = 0; j < COLUMNS; ++j) { cout << i << "," << j << " "; } cout << endl; } return 0; }
0 Comments
The biggest obstacle I will be teaching my learning's about programming. programming is very difficult for most, and it will be hard for me to help people when I myself might not know. although I will always try my best.
here we learn many new things, so take time to study this.
Char is a character, a letter of your choice, I will post a chart of the new parts of code that we used today in the next blog. // Game Stats // Demonstrates declaring and initializing variables #include <iostream> using namespace std; int main() { int score; double distance; char playAgain; bool shieldsUp; short lives, aliensKilled; score = 0; distance = 1200.76; playAgain = 'y'; shieldsUp = true; lives = 3; aliensKilled = 10; double engineTemp = 6572.89; cout << "\nscore: " << score << endl; cout << "distance: " << distance << endl; cout << "playAgain: " << playAgain << endl; //skipping shieldsUp since you don’t generally print Boolean values cout << "lives: " << lives << endl; cout << "aliensKilled: " << aliensKilled << endl; cout << "engineTemp: " << engineTemp << endl; int fuel; cout << "\nHow much fuel? "; cin >> fuel; cout << "fuel: " << fuel << endl; typedef unsigned short int ushort; ushort bonus = 10; cout << "\nbonus: " << bonus << endl; return 0; } this demonstrates the ability to use math within C++. write this code and study the results you get.
// expensive calculator // demonstrates built-in arithmetic operators #include <iostream> using namespace std; int main() { cout << "7 + 3 = " << 7 + 3 << endl; cout << "7 - 3 = " << 7 - 3 << endl; cout << "7 * 3 = " << 7 * 3 << endl; cout << "7 / 3 = " << 7 / 3 << endl; cout << "7.0 / 3.0 = " << 7.0 / 3.0 << endl; cout << "7 + 3 * 5 = " << 7 + 3 * 5 << endl; cout << "(7 + 3) * 5 = " << (7 + 3) * 5 << endl; return 0; } This time we are looking how to avoid typing std:: before every line of code we ever type in.
under"#include <iostream>" you want to type in "using namespace std;" // Game Over // A first C++ program #include <iostream> int main() { std::cout << "Game Over" << std::endl; return 0; } this is the very first program.
when righting a program you almost always want to have "#include <iostream>" as well as "int main()" std::cout << "Game Over" displays the the text in the "" "endl" ends the line and starts any code to go to the next, after most lines of code you want to put a semi colon. << separates different parts of code within the same line. // Game Over // A first C++ program #include <iostream> int main() { std::cout << "Game Over" << std::endl; return 0; } Today I will hopefully be able to post some pages from the book so you can read and then write the program yourself, and learn from it. Make sure you study the code when writing it not just mindlessly typing away, you wont learn anything. Programming with work your brain unlike any class you have taken in a long time. If you get upset make sure to take a walk and think about it. take a note pad with you for the chance you have ideas and figure it out during the walk.
If you have any questions make sure to leave a comment, I promise to get back to you as soon as possible. This site will help people learn programming as I learn it myself. The process will be slow at first of course, but over time we will get into more advanced, such as learning how to make the game Asteroids or even the game snake. through the years I hope to still be learning programming and I will be able to teach you how to program games that look close to the games you would have played on the SNES or the N64. Through time i hope to get a job in programming games that come out at current times and I hope to share my knowledge with you. Doing this process with you I hope to help you find what kind of programming you want to head into or if you want to program at all. I plan on posting not only texts for you to read but I hope to post voiced video tutorials of me programming and teaching you what I am doing and how you can do the same program with your own twist your how you may want it to be.
|
Jonathan N.Just a simple guy trying to help people understand programming along with me. We will be taking the journey of learning programming together. Archives
April 2016
Categories |