943,397 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3922
  • C++ RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Aug 20th, 2004
0

Re: New to C++, need help

Quote originally posted by RobinA ...
ok i fixed it now but got one more question (heres the final code i used) when i click run the program it opens but it closes itself in about 0.01 sec after it have opened. whats the wrong now with the code, and i dont get any errors when compiling.

# include <iostream>
int main()
{
using namespace std;
int tal1, tal2, produkt;
tal1=5;
tal2=11;
produkt=tal1*tal2;
cout <<"Produkten är" << produkt;
}
I am a total newbie to c++ myself however i THINK its something like:

C++ Syntax (Toggle Plain Text)
  1. # include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int tal1, tal2, produkt;
  6. tal1=5;
  7. tal2=11;
  8. produkt=tal1*tal2;
  9. cout <<"Produkten är" << produkt;
  10. cin >> mong;
  11. return 0;
  12. }

Basically it ends because it reached the end of the program, if you add an input to the end then the program isnt finished till you do the input.
I have not tested this and have no idea if it works, like i said im a c++ newbie too :o

YoungCoder
Reputation Points: 13
Solved Threads: 2
Junior Poster
YoungCoder is offline Offline
193 posts
since Aug 2004
Aug 20th, 2004
0

Re: New to C++, need help

YoungCoder i compiled the code and it didnt go it was cin that was the error but i erased that line ( cin >> mong then it worked like mine it opened and closed.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
RobinA is offline Offline
9 posts
since Aug 2004
Aug 20th, 2004
0

Re: New to C++, need help

ok i got it to work now the final code was


# include <iostream>
using namespace std;
int main()
{
int tal1, tal2, produkt;
tal1=5;
tal2=11;
produkt=tal1*tal2;
cout <<"Produkten is " << produkt;
}

and i compiled it in Visual C++ now and it worked.
Reputation Points: 11
Solved Threads: 0
Newbie Poster
RobinA is offline Offline
9 posts
since Aug 2004
Aug 20th, 2004
0

Re: New to C++, need help

Other than using :-
#include <iostream>
using namespace std;

you can also try to replace it with this:-
#include <iostream.h>

But it is adviceable to use the former as it is of the latest format.
Good Luck!
Reputation Points: 11
Solved Threads: 0
Newbie Poster
Pikachu is offline Offline
19 posts
since Aug 2004
Aug 21st, 2004
0

Re: New to C++, need help

Yea,using #include <iostream> is now the latest standard.

namespaces are something like a sealed off area of code,out side which you can use the same names with out conflicting with the name in the namespace scope.

You can also access namespace vars like namespace::std, std::cout

Have fun,ALSO learn to use the Standard Template Library (STL)
Reputation Points: 108
Solved Threads: 7
Posting Whiz in Training
FireNet is offline Offline
256 posts
since May 2004

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: Sending and receiving ARP packets
Next Thread in C++ Forum Timeline: Is c # slower than c/c++





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


Follow us on Twitter


© 2011 DaniWeb® LLC