943,754 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 546
  • C++ RSS
Nov 20th, 2008
0

help :S

Expand Post »
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.
  1. #include <stdio.h>
  2.  
  3.  
  4. int main (void)
  5. {
  6. int x;
  7. int y;
  8. int z;
  9. int min;
  10. printf("enter 3 numbers : ");
  11. scanf("%d %d %d", &x,&y,&z);
  12.  
  13. min=x;
  14. if (y<x && y<z)
  15. y=min;
  16. if (z<x && z<y)
  17. z=min;
  18.  
  19. printf("min is : ", min);
  20. return(0);
  21. }
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
ty for helping this newcommer


/* sorry for my bad english ı hope u could understand what ı meant */
Last edited by Ancient Dragon; Nov 20th, 2008 at 8:22 pm. Reason: add code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mstrofdrgns is offline Offline
5 posts
since Nov 2008
Nov 20th, 2008
0

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.
C++ Syntax (Toggle Plain Text)
  1. #include <iostream>
  2. using std::cout;
  3.  
  4. int main()
  5. {
  6. cout << "Hello World\n";
  7. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005
Nov 20th, 2008
0

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:

cpp Syntax (Toggle Plain Text)
  1. #include <iostream>
  2.  
  3. int main() {
  4. int x, y, z, min; // Don't forget you can declare multiple variables of the same type on the same line
  5.  
  6. std::cout<<"Enter 3 numbers: ";
  7. std::cin>> x >> y >> z; // When entering the three numbers you have to leave spaces between them here
  8.  
  9. min = x;
  10. if (y<x && y<z)
  11. y=min;
  12.  
  13. if (z<x && z<y)
  14. z=min;
  15.  
  16. std::cout<<"min is : " << min << std::endl; // This prints text with the first insertion operator '<<', and a variable with the second
  17. // I added an endline for the beauty of it
  18.  
  19. system("pause"); // Pauses the application
  20. return 0;
  21. }

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
Last edited by brechtjah; Nov 20th, 2008 at 8:29 pm.
Reputation Points: 26
Solved Threads: 9
Junior Poster in Training
brechtjah is offline Offline
92 posts
since Nov 2008
Nov 20th, 2008
0

Re: help :S

ty for your replies.

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

Click to Expand / Collapse  Quote originally posted by brechtjah ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mstrofdrgns is offline Offline
5 posts
since Nov 2008
Nov 20th, 2008
0

Re: help :S

void main(). C and C++ standards require main() to return an int.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,950 posts
since Aug 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Reading a file. Copying over to other file. Renaming. Renaming = -1?
Next Thread in C++ Forum Timeline: Homework Function Compile Errors





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC