C/C++ :: Converting Dollar Amount To String
May 18, 2014
I'm quite new to programming and working on an algorithm for the program so we would have to change that into a workable code for our final program.
This is the algorithm teacher gave us for reference (with the functional decomposition):
3.9.3 convertNetPay()
// convertNetPay(in netPay, out netPayString)
char * convertNetPay(float netPay);
void convertNetPay(float netPay, char * netPayString);
Algorithm:
convertNetPay(in netPay, out netPayString)
Declarations: numHuns, numTens, numOnes as integer
OnesTable as array[9] string = {"One", "Two","Three", ...."Nine"}
"One" --> 0
"Two" --> 1
"Three" --> 2
...
[Code] .....
So that goes my entire instruction on the assignment and I will start my code and be probably asking quite a bit of questions!
Here is my code so far:
Spoiler
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
void convertNetPay(float netPay, char *netPayString) {
int numHuns, numTens, numOnes;
[Code] .....
View 9 Replies
ADVERTISEMENT
Jan 26, 2014
I am currently using Xcode on a Mac to compile a c++ program. My class uses Codeblocks and I am having issues with the variable names and commands.
The assignment is to write a program that calculates the quarters, dimes, nickels, and pennies needed to input the amount of money. We have to apply the largest value coins first and use modulus for the remainder.
the input for turning in is: 398
This is idea I am getting...
#include <iostream>
int input;
int quarters, dimes, nickels, pennies;
cout<<"Enter dollar amount: ";
cin>> input;
quarters = inputquarters/.25;
[Code] ....
View 1 Replies
View Related
Feb 25, 2015
I'm trying to make a program that allows the user to input an arbitrary amount of numbers and finding the largest of all the inputs but I keep having problems with the output.
javascript:tx('
#include <iostream>
using namespace std;
//******************************************
//CLASS COMPARATOR
//******************************************
class comparator {
public:
comparator();
[Code] .....
And regardless of what numbers I enter, I always get the output of 10. Also I got the EOF idea from my textbook so if there is a better way of doing this I'd like to hear it. I don't know any clear ways that looks nice to end the while loop when the user doesn't have any more numbers to enter.
View 3 Replies
View Related
May 18, 2014
Code:
void convertNetPay(float netPay, char *netPayString){
int numHuns, numTens, numOnes;
char OnesTable[9][8]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char ResultString[10+1];
char TensTable[9][8] = {"Ten","Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
char TeensTable[9][10] {"Eleven","Twelve","Thirteen","fourteen","fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
float cents;
[Code] ....
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.
View 2 Replies
View Related
May 6, 2014
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++.
Code:
#include <iostream>
#include <fstream>
#include<string>
#include <cstdlib>
using namespace std;
bool parseTime(char* _timeStr, int& _hour, int& _min) {
[Code] ....
View 6 Replies
View Related
Dec 7, 2014
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.
View 1 Replies
View Related
May 18, 2014
void convertNetPay(float netPay, char *netPayString) {
int numHuns, numTens, numOnes;
char OnesTable[9][8]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char ResultString[10+1];
[Code] ....
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".
View 4 Replies
View Related
May 2, 2013
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;
[Code]....
View 1 Replies
View Related
Nov 22, 2013
I'm trying to convert a string into a integer and when I call stoi(line) it causes the program to crash.
int main() {
vector<int> numbers;
int i;
string line;
ifstream myfile ("example.dat");
[Code] ....
The file being read from looks like:
3
12
23
34
12 34
12 12
34 23
23 23
View 1 Replies
View Related
Feb 21, 2015
In my project i have to take the string valve and convert it into float
For example
100 will be 100.00
100.0012 will be invalid
100.00 will stay as it is
99 will be 99.00
I am thinking of using stof but i m stuck on how to set the precision of 2 ....
View 2 Replies
View Related
Apr 27, 2014
Quick code for converting strings to Dates in C++.
Example: What is the date:
User response: 12/05/14
Any way I can code this to recognize it as a date, and make it so that the date is sortable? Not referring to the system date, but a user input date.
View 4 Replies
View Related
Mar 27, 2015
I am trying to convert a 1d string array to a 2d but i couldnt do it. Heres my code so far,
for(i=0;str2d[i][j]='';i++)
{
for(j=0;str2d[i][j]=' ';j++)
{
str2d[i][j] = str1d[k];
k++;
}
}
str1d is a paragraph btw.I tried using NULL instead of '' but didnt work either.
View 5 Replies
View Related
Mar 19, 2012
how to convert from string to date in c++? Example: 17 mar 2012 to 17/03/2012
View 1 Replies
View Related
Sep 26, 2013
struct time
{ int t;
int h,m,s;
};
int main() {
time t;
int totalsecond;
char A[10],B[10];
[Code] ....
It gives error at line no 12.
View 5 Replies
View Related
Mar 30, 2014
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);
[Code]...
View 1 Replies
View Related
Mar 5, 2013
Here's the code I'm working on:
string* arrayPush(string *array, char **toks){
if(array[sizeofHistory -1].empty()){
//find the next available element
for(int i=0; i < sizeofHistory; i++ ){
[Code] ....
toks is an array of pointers to strings. I need to assign a toks to array[i].
View 10 Replies
View Related
Apr 11, 2014
I would like to convert a string variable to float.When acquiring data from text file, I use:
while( getline( ifs, temp )) {
numberOfFeatures++;
vecteur.clear();
string::size_type stTemp = temp.find(separateur);
number_descriptorEntries=0;
[code].....
the matrix that I obtain is of type vector<Vec> where Vec is a vector of strings.I want to convert each element of matrixe to a float.
View 3 Replies
View Related
Mar 11, 2013
I have a problem with converting a C++ string into a long double. In order to do this, I used the function strtold, but the result I get is only the integral part, that is: if for example the input string is 12.476, I only get 12 as the converted long double value. This happens with atof too.
Here is my code:
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
string test = "12.345";
long double test_longd = strtold(test.c_str(),NULL);
[Code] .....
View 3 Replies
View Related
Apr 17, 2014
For Example, it the entered string is: 0324152397 I want it to get stored in an array like-[0] [3] ...[7]. Secondly the string entered may be of any length that is defined only at run time. So, I also need to calculate string length. How could I do that.
View 2 Replies
View Related
May 18, 2014
I am having a lot of trouble extracting values from a string into a double array.
I have a string that looks something like this: "asdf 1.320 1 234.43 5.00000 3"
All I want to do is extract the doubles and store them in an array of doubles.
View 8 Replies
View Related
Nov 15, 2013
So I have to convert ("a499.9") into a char and a float while ignoring the a.
I have the string stored in a buffer and found how to get the char, 4. But I don't know how to get 99.9 as a float.
Here is my code so far.
#include <string>
using namespace std;
main() {
buffer = "a499.9";
[Code] ....
My output:
4
0
How to get that double out?
View 7 Replies
View Related
Jun 5, 2013
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.
View 3 Replies
View Related
Feb 8, 2015
I am writing a program that asks the user for their gender. I know that atoi converts arrays into integers, but I need the input from the user in the form of F or M into a char, and return it to the main function to be displayed at the end of the program.
string Employee::getgender(char gen)
{
cout << "Please enter your Gender: " << endl;
//atoi function would go here, what for char?
getline(cin,gen)
return gen;
}
View 1 Replies
View Related
Apr 15, 2014
I wrote the following code to solve this problem:
Read, from the keyboard, an integer greater than or equal to 1 (store it in a variable of type int).
Convert the integer to its representation in string format isolate each digit of the integer, convert it to the corresponding character (char).
Present the resulting string on the screen.
#include <iostream>
#include <ctime>
#include <cstring>
#include <ctype.h>
#include <cmath>
using namespace std;
unsigned GetNumberOfDigits (unsigned i) {
return i > 0 ? (int) log10((int) i) + 1 : 1;
[Code] ....
Why is it answering like this?
INTEGER ? 1999
STRING : œ
View 5 Replies
View Related
Jun 15, 2014
So I have problem with my code, I'm trying to convert string to long and then string to double, but I get this when I compile it:
terminating with uncaught exception of type std::invalid_argument: stod: no conversion
I was thinking if there is a way to do this without using (stol) or (stod)
Market::Market(string filename)
{
string line, word, date, stockprice;
long realdate;
[Code].....
View 14 Replies
View Related
May 16, 2014
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.
Code:
void convertNetPay(float netPay, char *netPayString) {
int numHuns, numTens, numOnes;
char OnesTable[9][8]={"One","Two","Three","Four","Five","Six","Seven","Eight","Nine"};
char ResultString[10+1];
[code].....
View 3 Replies
View Related