I have a vector<string> of times that I want to convert to vector<double>. The time string is in the form 00:00.000. Is there a STL or something like it algorithm or function to do this, otherwise what would be the best way to do this with a function.
I have an assignment that is due on monday I am stuck on this function. I have to convert my netpay which is a float to a string So if i have 356.26 it should output the sum of three hundred fifty-six and 26/100 dollars my program function works for the sum of three hundred but after that it spits out garbage.
Question: A computer uses 10 bits to store integers with 1 bit for a sign. It stores an approximation of real numbers in 10 bits. The first bit of the first five is the sign of the mantissa and the other four bits are the mantissa. The first bit of the second five is the sign of the exponent and the other four the exponent.
1)What is the range of integers?
2)what is the range of real numbers(Float Type)
The first question was simple. I just found the smallest 10 digit binary number 1000000000 = -512 and then found the largest 10 digit binary number which would have to be 0111111111 = 511, therefore the range of integers is from -512 to 511.
For the second question - I am either making this harder than it is, or it really is a challenging question. So I followed the steps and first I was thinking I would take the number 1000000000 and convert this to a decimal (assuming its a 10 bit float)...But, can you even do this with a 10 bit float??
I ended up getting 1000000000 (after denormalizing) = .000100000 = 0.625.. would that be the minimum range? If so, then I know what I need to do to find the maximum , but if not - then I am really lost.
My Process was:
1.00000 X 2^(-4) = my final result of 0.625 after converting.
I have to convert my netpay which is a float to a string So if i have 356.26 it should output the sum of three hundred fifty-six and 26/100 dollars my program function works for the sum of three hundred but after that it spits out garbage.
I want a code that can convert floating/double value into string/char array(char arr[]) and also it can be run on Boreland C++ 5.02
Here I've a code but it doesn't show all the numbers. Instead, it's showing in exponential form which I don't want!!
int main() { char* str = new char[30]; float flt = 2.4567F; sprintf(str, "%.4g", flt ); cout<<str<<endl; //Exponential form even after 6 digits without decimal return 0; }
void reverse(char *in, int isize) { char t = 0; for( int a = 0; a < isize / 2; a++ ) { t = in[a]; in[a] = in[(isize - 1) - a]; in[(isize - 1) - a] = t; [Code] .....
s: float:123456 s:123456
The function i made is working fine, exacly how cout << float is working. The problem is i think my function is not really effective. By that i mean my function is doing alot of useless stuff to do what i want and there have to be a better way.
The rule is that you can not use other functions, only playing with loops and operators.
I am working with a XML serializer. I wonder if I am creating a text element (xerces). But the value I am after is a float, how do I convert it into a std::string ....
So, I'm supposed to do : Create a function with unlimited number of arguments, which forms a dynamic string based on the following form (%d, %s, %f, %lf, %c), with the following prototype:
char*create(char*form, ...);
The function is supposed to have the following output:
create("Peter is %d years old and is in %s-%c class.",7,"second",'A'); -> Peter is 7 years old and is in 7-A class. create("His GPA is %lf.",4.96); -> His GPA is 4.96. create("His favourite subject is math!"); -> His favourite subject is math!
The part with %d and %s string was not that hard, but now I'm supposed to convert %f and %lf to string, I've tried using sprintf but I've had no luck so far, another problem is the fact that I've gotta use lists to complete the task. I've been trying to convert float to string for the past 2 hours, but I'm drawing a blank now.
I'm reading lines from a text file in C++ which contains integer + string + float number(like 3,67 with comma) + string in this order. I need the float number to sort the lines but I couldn't manage to separate the data into the types I can use so far. I tried different kind of functions and the best I could do was such a code;
void main (){ ifstream records; records.open("records.txt"); int id; string line; char name[100]; float gpa;
[Code] ....
This fails at reading the floating number which has comma in it and then last string is read as string starting with the comma and rest of the number. An output example is:
698 John 3 ,67
It doesn't read last string on the line as well. I understand that part but simply I need another read but what I want exactly is to separate one line using "tab" as a seperator into proper data types and then using the numbers as integers, and the grades as floating numbers. How Can I do this?
I was going over this with a friend and it seems as though getline() is not reading anything in and thus throwing the abort error. I'm not sure why this is because I've included the textfile, with the correct name of course, in both the regular file location and the debug folder. I ask for user input and the user then inputs the name of the file they want, I do some required things behind the scenes and display the results for them in a cmd window. I've included pastebin files for both my header and cpp files because it is far to large for one post I shall, however, post the full code in the comments.
Quick Code
The problem occurs on line 159. I'm assuming once this line is fixed, line 163 will have the same problem.
// Read regular price getline(nameFile, input, '$'); vectorList[count].regPrice = stof(input.c_str());// Casts string to a float // Read sale price getline(nameFile, input, '#'); vectorList[count].salePrice = stof(input.c_str());
I have to convert my netpay which is a float to a string So if I input a value of say, 356.26 it should output "the sum of three hundred fifty-six and 26/100 dollars" . My program function works for the sum of three hundred but after that it spits out garbage.
How will I add the existing content of the text file to the newly inputed date(hoursworked & minsWorked) to compute the total number of hours works. I'm just a beginner in using Visual basic C++.
I'm trying to find a way to accuratley convert a double in the form of a bank account number stored in a file into a string representing the number returned by a file.
BASICALLY, I have to convert netpay (float to string). Theoretically if I have 666.66, my program here should output the sum of "six hundred sixty-six and 66/100 dollars".
i think i need to convert a double to a string, we are working in visual studio doing a program. when i run the calculator i'm not getting the answer i need instead its giving me 0.0 when it should be reading 0.5, here is the code i'm using
{int width; int height; int area; double gop; String ^strWidth; String ^strHeight; String ^strArea; String ^strGop; strWidth=width1->Text;
In this program, I have to ask the user for an employee, then the program will check to see if the file for that employee exist, if it doesnt then it will automatically create the file.
ReadNew function reads the file....check to see if it exist
CreateNew function creates a new file.
In my code I have no problem with the first part of reading file.. and my createnew function works in other programs where I am asking for input of file name to create the file name. However in this code I cannot figure how to automatically pass the input filename from the ReadNew function to the CreateNew function. I can't ask the user to enter the name a second time, so I have to pass the input filename into both functions. Here is my code.
Code:
//Create a file, append to it, and read it. #include <iostream> #include <fstream> #include <string.h> #include <stdio.h> using namespace std; char filename[256]; string n; string filelist; void CreateNew(ofstream & FileNew);