Can you help me to develop a program which integers are placed in brackets fractions in quotation marks, and insert it in text file, that's it.
Printable View
Can you help me to develop a program which integers are placed in brackets fractions in quotation marks, and insert it in text file, that's it.
What have you done so far? (Besides, I note that your problem description is very vague, e.g., how do you obtain input?)
I just need the simplest way to do excercise.
i think there could be used this algoritm:
if(a==round(a)){
Insert in ()
}
else {
insert in ""
}
But im zero at C++, i just need this stupid excercise to be done :D
a small description, people writes and number in programm, then if its string, then it inserts it in text file in breckets, if you enter somthing like 3,14 then it inserts in " " and thats it.
You're doing a terrible job at explaining your problem. Regardless, nobody will do it for you. Try it yourself and ask for assistance when you're stuck. As it is, I doubt anybody has any idea what you're trying to do.
I would suggest you start by reading an introductory book to C++. It will help you greatly for the future.
People obviously don't want to do your homework for you, but you could do something along the lines of:
This isn't exactly what you asked for, but I didn't feel like spending too much time trying to decipher your question.Code:int main()
{
char stringIn[40];
fstream fin, fout;
fin.open("pathIn.txt", ios::in);
fout.open("pathOut.txt", ios::in);
while(!fin.eof())
{
fin >> stringIn[40];
if(isDouble(stringIn))
fout << "[" << stringIn << "]" << endl;
else
if(isInt(stringIn))
fout << "\"" << stringIn << "\"" << endl;
else
if(isString(stringIn))
fout << stringIn << endl;
}
}
Now, there are more than likely header files out there that have isDouble functions, but you can make your own.
For example:
Don't forget to include function prototypes.Code:bool isString(char stringIn[40])
{
if(!isInt(stringIn) && !isDouble(stringIn))
return true;
else
return false;
}
bool isInt(char stringIn[40])
{
for(int i = 0; i <= 39; i++)
{
if(stringIn[i] > '9' || stringIn[i] < '0')
return false;
}
return true;
}
bool isDouble(char stringIn[40])
{
for(int i = 0; i <= 39; i++)
{
if((stringIn[i] > '9' || stringIn[i] < '0') && stringIn[i] != '.')
return false;
}
if(isInt(stringIn)) //implying that a double must have a '.'
return false;
return true;
}
Note: I wrote this code in codeguru's "compiler," there are bound to be errors.
The decimal separator is not everywhere in the world the same. In the states it's a . (dot) but for example in belgium it's a , (comma).