I want to make a program which ask the user to enter double values and stores it in a file. The inputs process ends when the user enters cntr+d. Can someone suggest how to do it ? i wrote the following code but it doesn't work !

ofstream file("test.txt");
double num;
char ch;

while ( int(ch) != 4 )
{

   cout << " Enter Value: ";
   cin >> num >> ch;
   file << num;

}

Waiting for your help ! :-)

Recommended Answers

All 2 Replies

I managed to to solved it.

string num;
    ofstream file("test.txt");
    
    do 
    {
          cout << "Enter Double: ";
          cin >> num; // >> ch1 >> ch2;
          file << num << " ";
          
    } while ( ( int(num[0]) != 4) );

I managed to to solved it.

Are u sure?

sth tells me u r not :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.