RSS Forums RSS

help :S

Please support our C++ advertiser: Programming Forums
Thread Solved
Reply
Posts: 5
Reputation: mstrofdrgns is an unknown quantity at this point 
Solved Threads: 0
mstrofdrgns mstrofdrgns is offline Offline
Newbie Poster

help :S

  #1  
Nov 20th, 2008
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 7:22 pm. Reason: add code tags
AddThis Social Bookmark Button
Reply With Quote  
Posts: 13,866
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1231
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: help :S

  #2  
Nov 20th, 2008
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";
}
Reply With Quote  
Posts: 89
Reputation: brechtjah is an unknown quantity at this point 
Solved Threads: 9
brechtjah's Avatar
brechtjah brechtjah is offline Offline
Junior Poster in Training

Re: help :S

  #3  
Nov 20th, 2008
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:

  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 7:29 pm.
Reply With Quote  
Posts: 5
Reputation: mstrofdrgns is an unknown quantity at this point 
Solved Threads: 0
mstrofdrgns mstrofdrgns is offline Offline
Newbie Poster

Re: help :S

  #4  
Nov 20th, 2008
ty for your replies.

Originally Posted by Ancient Dragon View Post
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

Originally Posted by brechtjah View Post
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
Reply With Quote  
Posts: 13,866
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1231
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Most Valuable Poster

Re: help :S

  #5  
Nov 20th, 2008
void main(). C and C++ standards require main() to return an int.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Views: 332 | Replies: 4 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:38 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC