Tutorials on c++?

  • lostsoul
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 26, 2003
  • Posts: 39
  • Loc: Ocala, FL
  • Status: Offline

Post October 27th, 2003, 11:41 am

Btw how hard is c++ to learn :/ lol for a 16 year old that is.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post October 27th, 2003, 11:41 am

  • Kasracer
  • Banned
  • Banned
  • No Avatar
  • Joined: Oct 26, 2003
  • Posts: 26
  • Loc: Maryland
  • Status: Offline

Post October 27th, 2003, 11:53 am

lostsoul wrote:
Hmm i put a conversion code and compile it i open the msdos .cpp file and i type in number and it automatically closes dos... its suposed to convert the code heh

Time to learn C++.

For one, the Window should close. You are NOT supposed to just double click it. It is a program run from command prompt.

To let you know:
Code: [ Select ]
#include <stdio.h> //Deprecate header file, use #include <cstdio>
#include <iostream.h> // Deprecate header file, use #include <iostream>
//Since you should use #include <iostream>, you are required to put the using namespaces directive
//afterwards so it would be 'using namespace sdt;' under the #includes

int main(int nNumberofArgs, char* pszArgs[])//The arguements arn't required when you arn't accepting arguments in the program
{
  
  int nCelsius;
  cout << "Enter the temperature in Celsius:"; //no where in the program do you use << endl;. This means
    //the buffer never gets flushed. You should atleast use << endl; when you want a line to end
  cin >> nCelsius; //fine for now, but you'll want to move to getline() eventually

  int nFactor;
  nFactor = 212 - 32; // fine but could be combined into 1 statement.

  int nFahrenheit;
  nFahrenheit = nFactor * nCelsius/100 + 32;

  cout << "Fahrenheit value is:";
  cout << nFahrenheit;

  return 0; // return 0 is NOT required and shouldn't be used in C++ for the funciton main().
    //main() will ALWAYS return an int and 0, so you can elide return 0;
}
  1. #include <stdio.h> //Deprecate header file, use #include <cstdio>
  2. #include <iostream.h> // Deprecate header file, use #include <iostream>
  3. //Since you should use #include <iostream>, you are required to put the using namespaces directive
  4. //afterwards so it would be 'using namespace sdt;' under the #includes
  5. int main(int nNumberofArgs, char* pszArgs[])//The arguements arn't required when you arn't accepting arguments in the program
  6. {
  7.   
  8.   int nCelsius;
  9.   cout << "Enter the temperature in Celsius:"; //no where in the program do you use << endl;. This means
  10.     //the buffer never gets flushed. You should atleast use << endl; when you want a line to end
  11.   cin >> nCelsius; //fine for now, but you'll want to move to getline() eventually
  12.   int nFactor;
  13.   nFactor = 212 - 32; // fine but could be combined into 1 statement.
  14.   int nFahrenheit;
  15.   nFahrenheit = nFactor * nCelsius/100 + 32;
  16.   cout << "Fahrenheit value is:";
  17.   cout << nFahrenheit;
  18.   return 0; // return 0 is NOT required and shouldn't be used in C++ for the funciton main().
  19.     //main() will ALWAYS return an int and 0, so you can elide return 0;
  20. }



Revised version of your code:
Code: [ Select ]
#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
  
  int nCelsius;
  cout << "Enter the temperature in Celsius: ";
  cin >> nCelsius;

  int nFactor = 212 - 32;
  int nFahrenheit = nFactor * nCelsius/100 + 32;

  cout << "Fahrenheit value is: " << nFahrenheit << endl;
    system("PAUSE");
}
  1. #include <cstdio>
  2. #include <iostream>
  3. using namespace std;
  4. int main()
  5. {
  6.   
  7.   int nCelsius;
  8.   cout << "Enter the temperature in Celsius: ";
  9.   cin >> nCelsius;
  10.   int nFactor = 212 - 32;
  11.   int nFahrenheit = nFactor * nCelsius/100 + 32;
  12.   cout << "Fahrenheit value is: " << nFahrenheit << endl;
  13.     system("PAUSE");
  14. }


See how much cleaner that is? Also, if you don't want to transverse the directories in command prompt to run your program from command prompt, #include <cstdio> in your program, then use system("PAUSE"); in your code when you want the program to stop so you can view the output.

I would recommend using a new book and maybe finding a new tutorial online, which is usually hard to find.

lostsoul wrote:
Btw how hard is c++ to learn :/ lol for a 16 year old that is.

C++ is an easy language. Once you learn the syntax, it isn't difficult at all. Some code may look complex as hell, but it usually isn't and once you get a grasp of things, you can understand it.

C++ is actually one of the easier languages.
  • lostsoul
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 26, 2003
  • Posts: 39
  • Loc: Ocala, FL
  • Status: Offline

Post October 27th, 2003, 12:10 pm

ok msdos is something i really never cared to experiment with so im in msdos prompt how do i run the exe from there? D:\Program Files\c++ is the directory my file is stored in. but dos prompt says c:\WINDOWS> lol hope i dont sound stupid asking that :/
  • Kasracer
  • Banned
  • Banned
  • No Avatar
  • Joined: Oct 26, 2003
  • Posts: 26
  • Loc: Maryland
  • Status: Offline

Post October 27th, 2003, 12:19 pm

lostsoul wrote:
ok msdos is something i really never cared to experiment with so im in msdos prompt how do i run the exe from there? D:\Program Files\c++ is the directory my file is stored in. but dos prompt says c:\WINDOWS> lol hope i dont sound stupid asking that :/
You could do like I said and just use system("PAUSE"); at the point in your code when you want it to pause.

Otherwise, type this
Code: [ Select ]
cd\
chdir /d d:
cd "Program Files"
cd c++
  1. cd\
  2. chdir /d d:
  3. cd "Program Files"
  4. cd c++

Then just find the executable's name, type it in and hit enter.
  • lostsoul
  • Beginner
  • Beginner
  • No Avatar
  • Joined: Oct 26, 2003
  • Posts: 39
  • Loc: Ocala, FL
  • Status: Offline

Post October 27th, 2003, 12:23 pm

Ok thanks i got it :)

Post Information

  • Total Posts in this topic: 20 posts
  • Users browsing this forum: No registered users and 257 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.