Some help plz!

This is a discussion on Some help plz! within the C++ Programming forums, part of the General Programming Boards category; Hello.. can anybody helps me? i'm trying to write a c++ program.. that does like this... enter a number like ...

  1. #1
    Registered User
    Join Date
    Jan 2006
    Location
    Jerusalem
    Posts
    11

    Exclamation Some help plz!

    Hello.. can anybody helps me? i'm trying to write a c++ program.. that does like this... enter a number like 123 and the program should read it in reverse... like 321!
    i did it.. but there z something wrong... i cant guess where z it...
    Code:
     #include <iostream.h>
     void main(){
      int num,n,x;
    cout<<"Enter a positive number please\n";
    cin>>num;
       for(int j=1; num>=j; j*=10){
          for(int i=10; x>=n   ; i*=10){
             n= num%i;
             x= n/j;
             cout<<x;
    }
    }
    if i put 12.. it would give me 212121..................... and if i give it 123 it wuld give me infinity and wrong numbers.. like 3231321123..... !!!! :confused: ... :(

  2. #2
    ZuK
    ZuK is offline
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    I do not understand the logic of your program. But I do understand that you use uninitialized variables ( x and n ).
    So your inner loop might or might not run at all.
    Kurt

  3. #3
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,806
    Code:
    #include <iostream.h>
    That should be just iostream (without the .h extension) and you'll likely need to put a using namespace std; line under that for now until you understand about namespaces:
    Code:
    #include <iostream>
    using namespace std;


    Code:
    void main(){
    The function main should always return an int.



    Code:
    for(int i=10; x>=n   ; i*=10){
    One problem is that n and x are not initialized at this point in the program, they could have almost any value in it.



    These types of problems are often better handled by reading the input in as a text string instead of an integer. It is then easy to use text manipulation to reverse the characters making up the string.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  4. #4
    Registered User
    Join Date
    Jan 2006
    Location
    Jerusalem
    Posts
    11
    thnx alot for helpin' me! but about the ogic of my program!! dont ask me! ask the programmer who wrote it.. cuz actually i was studyin' and i found this q in the homework i had to do!! so i tired to do it!!!
    and about the <iostream> without .h... i dont think that it goes with my Borland c++ 4.52!

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    183
    I'm no expert myself, but what are the errors you get if you use :

    Code:
    #include <iostream>
    You sure it's Iostream that's causing what ever problem it is ? They should both be compatible. (Compiler and Iostream )

  6. #6
    Registered User
    Join Date
    Jan 2006
    Location
    Jerusalem
    Posts
    11
    well yes.. i'm so sure... <iostream.h> has nothing to do with the errors i have .. and if i tried to use
    Code:
    # include <iostream>
      using namespace std;
    it would tell me
    Code:
    Compiling NONAME00.CPP:
    Error NONAME00.CPP 1: Unable to open include file 'IOSTREAM'
    Error NONAME00.CPP 2: Declaration syntax error
    Error NONAME00.CPP 4: Undefined symbol 'cout' in function main()
    .... !

  7. #7
    Registered User
    Join Date
    Jan 2006
    Location
    Jerusalem
    Posts
    11
    well yes.. i'm so sure... <iostream.h> has nothing to do with the errors i have .. and if i tried to use
    Code:
    # include <iostream>
      using namespace std;
    it would tell me
    Code:
    Compiling NONAME00.CPP:
    Error NONAME00.CPP 1: Unable to open include file 'IOSTREAM'
    Error NONAME00.CPP 2: Declaration syntax error
    Error NONAME00.CPP 4: Undefined symbol 'cout' in function main()
    .... !

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Borland 4 is stone age, but you're right, it doesn't have the versions without .h.

    Unless you really still use MS-DOS, I highly advise that you get a proper compiler. You can get Bloodshed Dev-C++, or various free offers from MS.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can any1 plz make this assignment
    By jean in forum C Programming
    Replies: 17
    Last Post: 05-13-2009, 10:19 PM
  2. plz help me...
    By sweetchakri in forum C Programming
    Replies: 1
    Last Post: 03-03-2009, 11:50 PM
  3. [Request] Need Help Plz
    By TylerD in forum Tech Board
    Replies: 4
    Last Post: 01-03-2009, 09:54 AM
  4. Anyone plz help me
    By Rose_Flowers in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 09-17-2003, 01:01 PM
  5. help plz plz
    By nsssn73 in forum C++ Programming
    Replies: 2
    Last Post: 06-03-2002, 09:44 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21