#include <iostream.h>
#include <conio.h>

int main()
{  
    int number[5];
    cout<< " enter the number \n";
    
    for (int i=0;i<=5;i++)
    {   while (i!=$)
        {
         cin >> number[i];
        }
     }
     for (int i;i<='null';i++)
     { cout<< "number="<<number[i];
     }
        getch();
    return (0);
    }

i have used a special character which tells the user to press$ when he is out of inputs but it shows a error.. need help

Edited 4 Years Ago by WolfPack: Added code tags

Please put your code in code-tags in the future, to preserve formatting. Since the site does not preserve formatting by default, you should always put code samples between code tags.

#include <iostream.h>
#include <conio.h>

int main()
{  
    int number[5];
    cout<< " enter the number \n";

    for (int i=0;i<=5;i++)
    {   while (i!=$)
        {
         cin >> number[i];
        }
     }
     for (int i;i<='null';i++)
     { cout<< "number="<<number[i];
     }
        getch();
    return (0);
}

I see a few issues with this code as it is. First off, the 'special character' needs to be in single quotes. Second, and conversely, the 'null' should not be in single quotes, as it is not a character literal but a defined constant; also, it needs to be in all-caps (NULL). Third, because you are reading the input into an integer value directly, you'll never read in the dollar sign anyway, so the loop would never end.

BTW, what compiler are you using? Modern compilers should not accept the older <iostream.h> header, but should instead always use <iostream> (without the ".h" extension). On a related note, the <conio.h> is not standard, and while some modern compilers will support it, it is specific to the older DOS systems (which is not the same as the Windows Console).

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You can add [CODE] tags automatically by selecting your code with the mouse, then clicking on the [CODE] button at the top of the editing window. You can also add them manually simply by typing in [CODE] at the beginning of the code section, and [/CODE] at the end of the code section.

[CODE]
In the editor it will look like this,
[/CODE]

whereas when it is actually posted,

it will look like this.

BTW, I've edited my earlier post somewhat, so you may want to r-read it.

Edited 4 Years Ago by Schol-R-LEA: n/a

Please put your code in code-tags in the future, to preserve formatting. Since the site does not preserve formatting by default, you should always put code samples between code tags.

#include <iostream.h>
#include <conio.h>

int main()
{  
    int number[5];
    cout<< " enter the number \n";

    for (int i=0;i<=5;i++)
    {   while (i!=$)
        {
         cin >> number[i];
        }
     }
     for (int i;i<='null';i++)
     { cout<< "number="<<number[i];
     }
        getch();
    return (0);
}

I see a few issues with this code as it is. First off, the 'special character' needs to be in single quotes. Second, and conversely, the 'null' should not be in single quotes, as it is not a character literal but a defined constant; also, it needs to be in all-caps (NULL). Third, because you are reading the input into an integer value directly, you'll never read in the dollar sign anyway, so the loop would never end.

BTW, what compiler are you using? Modern compilers should not accept the older <iostream.h> header, but should instead always use <iostream> (without the ".h" extension). On a related note, the <conio.h> is not standard, and while some modern compilers will support it, it is specific to the older DOS systems (which is not the same as the Windows Console).

i use dev c++ i used conio.h for getch(). i tried using cin.get but it seems not to work. an y hot use the .h extension? do elaborate plz

Edited 3 Years Ago by mike_2000_17: Fixed formatting

After you read your file using cin, use the cin.ignore(); to clear the buffer.
Please correct me if I'm wrong.
And then the cin.get() will work.

cin>>a; cin.ignore();
//more code;
cin.get();
return 0;

As for the '.h' extension, the main issue is that when the C++ standard was introduced in 1998, they changed how many things worked. One of the key changes was the use of the namespace 'std' for most of the standard C++ library. Now, all of the stream I/O objects such as cin and cout would be part of the std namespace, which would make it easier for 3rd party library developers to design classes without worrying about conflicting with the standard library.
Because this (and other recent changes) broke the older code, it was decided that the new headers wouldn't have the '.h' extension, so that code which used the older headers would still use those versions of the headers. However, that was just for backwards compatibility; new code should always use the new headers, as they contain a number of improvements over the older headers.

Speaking of older software, if you have a choice, I would recommend replacing Dev-C++ with a newer IDE such as Code::Blocks. Dev-C++ hasn't been updated in six years and several problems in it were never fixed.

This article has been dead for over six months. Start a new discussion instead.