Author Topic: Learning C++  (Read 927 times)

I read the first chapter of "C++ for Dummies", so I did this on my own.
Code: [Select]
// Multiplier.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <cstdio>
#include <cstdlib>
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
int x;
std::cout << "Enter the first number:";
std::cin >> x;

int y;
std::cout << "Enter the second number:";
std::cin >> y;

int z;
z = x * y;

std::cout << "The product is:";
std::cout << z << std::endl;

system("PAUSE");
return 0;
}



It says,

Please enter the first number: (enter 5)
Please enter the second number: (enter 4)
The product is: (20)
Press any key to continue...



Very, very, very basic.

Wow that went away fast, bump.

It went away because nobody cares enough to say anything about it. Any dumbass can copy stuff out of a "??? for Dummies" book.

While this is bumped.

I took a class in highschool on visual basic. Was all so simple. I made a magic 8ball program where people on the computer entered answers that added to its database of possible random answers.
And the app rememberd already asked questions so it would repeat the same answers again if they were reasked.
I left it on 6 computers in the school lab. And by the endof the month they had thousands of questions and answers built up.

In the end, at least every guy's loveual preference in that school had been questiond.

And that is my short uninteresting story.

I dislike the way they did that. For one you don't need all those include files.


#include <iostream>
using namespace std;


You didn't need any parameters in main, and the way main is initialized as _tmain is confusing.

int main()
{
     int x, y, z;

     cout<< "Enter the first number: ";
     cin>> x;

     cout << "Enter the second number: ";
     cin>> y;

     z = x * y;

     cout<< "The product is: " << z <<endl;

     return 0;
}

If you are using Visual Studio, the system pause is unnecessary if you "Start without Debugging", or Ctrl + F5.

Also, make sure you don't make variables so ambiguous. Bad style.

The book we were recommended to get in my college course was Absolutely C++. It's probably a better resource then what you have. Another good idea is learning C before C++, it's more basic. A Book on C is a good resource for that.