DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   help :S (http://www.daniweb.com/forums/thread158677.html)

mstrofdrgns Nov 20th, 2008 8:16 pm
help :S
 
hey there ,

Im taking C++ courses in my collage (so ım a newbie) and they are teaching programing language a bit different from the examples in this forum.
#include <stdio.h>


int main (void)
{
    int x;
    int y;
    int z;
    int min;
    printf("enter 3 numbers : ");
    scanf("%d %d %d", &x,&y,&z);
   
    min=x;
    if (y<x && y<z)
      y=min;
    if (z<x && z<y)
      z=min;

    printf("min is : ", min);
    return(0);
}
well this works too, but ı can not understand most of the programs in this forum

is there any place to learn how to write that " cout << ".... ; " thing or something like this :S
ty for helping this newcommer:)


/* sorry for my bad english ı hope u could understand what ı meant */

Ancient Dragon Nov 20th, 2008 8:27 pm
Re: help :S
 
That is C code, not C++. Are you sure you are in a c++ class?

for a fstream tutorial click here.

cout is quite easy to learn. First you have to include <iostream> header file -- it does not have a .h extension. Then declare the std namespace.
#include <iostream>
using std::cout;

int main()
{
    cout << "Hello World\n";
}

brechtjah Nov 20th, 2008 8:28 pm
Re: help :S
 
If you want to use cout and cin you'll have to include <iostream> and use namespace std.
A sample program is something like this:

#include <iostream>

int main() {
  int x, y, z, min;    // Don't forget you can declare multiple variables of the same type on the same line

  std::cout<<"Enter 3 numbers: ";
  std::cin>> x >> y >> z;        // When entering the three numbers you have to leave spaces between them here

  min = x;
  if (y<x && y<z)
    y=min;

 if (z<x && z<y)
    z=min;

  std::cout<<"min is : " << min << std::endl;            // This prints text with the first insertion operator '<<', and a variable with the second
  // I added an endline for the beauty of it

  system("pause");  // Pauses the application
  return 0;
}

It's really not that hard, a good site would be: http://www.java2s.com/Tutorial/Cpp/0...0040__cout.htm
By the way, why give void as an argument to main?

Hope this helps, if you have any questions just post them ^^

EDIT: bah, Ancient Dragon beat me to it

mstrofdrgns Nov 20th, 2008 8:42 pm
Re: help :S
 
ty for your replies.

Quote:

Originally Posted by Ancient Dragon (Post 741006)
That is C code, not C++. Are you sure you are in a c++ class?

well, i am taking introduction to programing class and they are telling us that " we are teaching you c++" but im not so sure about this now :)

Quote:

Originally Posted by brechtjah (Post 741008)
By the way, why give void as an argument to main?

i have no clue about this they just tought us to do that this way and when i ask assistants about it, they just dont explain us clearly .

ty again

Ancient Dragon Nov 20th, 2008 8:52 pm
Re: help :S
 
void main(). C and C++ standards require main() to return an int.


All times are GMT -4. The time now is 11:46 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC