| | |
Arrays, Strings, ConCat??? Please help
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
I am at the end of my first term in my C++ classes. I have managed well so far, but this program is completely frustrating me! Please help me figure what to do.
Okay my assignment is kind of complicated for me.....here is what I am supposed to do, followed by the code that I have so far. I know that I still have quite a bit to do, but I am completely stuck at this point, with no clue how to get to where I want to be.
My program should output:
Commissions are calculated using a 0.07 value.
etc...
I am supposed to read the info from two input files (sales in one, and names in two) then create arrays for each. Determine commission randomly by generating percentage between .05 and .10 (Is there a way that I could .10 to print like that? In my current code it always reads as .1). Then I need to calculate the commission using sales and the generated number. I'm baffled by this, since I can't just multiply the numbers, I think I need to convert them, but am unsure how. My other BIG problem is how can I get the format to print the Sales, Name, and Commission on each line? There is a couple other things like sorting and printing to output file, but I'm pretty sure I can do that.
Okay my assignment is kind of complicated for me.....here is what I am supposed to do, followed by the code that I have so far. I know that I still have quite a bit to do, but I am completely stuck at this point, with no clue how to get to where I want to be.
My program should output:
Commissions are calculated using a 0.07 value.
C++ Syntax (Toggle Plain Text)
Sales Name Commission 2000.98 Abbott, Sue 140.07 950.12 Green, John 66.51 875.50 Jones, Mary 61.29
I am supposed to read the info from two input files (sales in one, and names in two) then create arrays for each. Determine commission randomly by generating percentage between .05 and .10 (Is there a way that I could .10 to print like that? In my current code it always reads as .1). Then I need to calculate the commission using sales and the generated number. I'm baffled by this, since I can't just multiply the numbers, I think I need to convert them, but am unsure how. My other BIG problem is how can I get the format to print the Sales, Name, and Commission on each line? There is a couple other things like sorting and printing to output file, but I'm pretty sure I can do that.
C++ Syntax (Toggle Plain Text)
// #include <iostream> #include <fstream> #include <string> #include <iomanip> #include <cstdlib> #include <ctime> #include <sstream> using namespace std; void Print(); void ReadSales(); void ReadNames(); float getrand(); int main() { Print(); ReadSales(); ReadNames(); system("pause"); return 0; } void ReadSales() { char sales [5][15]; ifstream myfile("File one.txt"); if(myfile.is_open()) { while(!myfile.eof()) { for (int i = 0; i < 4 ; i++) { myfile.get(sales[i],8,'\0'); cout << sales[i]; } } cout << endl; } else cout << "Unable to load file!" << endl; } void ReadNames() { char name [5][15]; ifstream myfile2("File two.txt"); if(myfile2.is_open()) { while(!myfile2.eof()) { int sizeOfFile = 0; for (int j = 0; j < 4 ; j++) { myfile2.get(name[j],15,'\0'); sizeOfFile++; } for (int j = 0; j < sizeOfFile; j++) { cout << name[j]; } } cout << endl; } else cout << "Unable to load file!" << endl; } void Print() { cout << "Commissions calculated using a " << getrand() << " value." << endl << endl; cout << "Sales" << setw(16) << "Name" << setw(32) << "Commission" << endl << endl; } float getrand() { srand(unsigned(time(0))); float commission = (rand() % 6 + 5.0)/100; return commission; }
Last edited by cscgal; Oct 2nd, 2008 at 10:54 am. Reason: Added code tags
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 1
I didn't really read your code as I am in a hurry.
this might be long and consume a lot of memory but you sho;uld try it anyway: why don't you take input from a file and store it into two parallel arrays. After storing that information I think you should use the random function to generate a number and use that number to point to whatever index will be displayed.
If this is not helpful sorry it's all i've got since you didn't highlight the keypoints and I don't have a lot of time.
goodluck
this might be long and consume a lot of memory but you sho;uld try it anyway: why don't you take input from a file and store it into two parallel arrays. After storing that information I think you should use the random function to generate a number and use that number to point to whatever index will be displayed.
If this is not helpful sorry it's all i've got since you didn't highlight the keypoints and I don't have a lot of time.
goodluck
•
•
Join Date: Sep 2008
Posts: 4
Reputation:
Solved Threads: 0
Sorry this is what I was having trouble with:
Then I need to calculate the commission using sales and the generated number. I'm baffled by this, since I can't just multiply the numbers, I think I need to convert them, but am unsure how. My other BIG problem is how can I get the format to print the Sales, Name, and Commission on each line?
I still need to create a third array that uses sales array and rand commission and since thier not same type I don't know how to convert. Then I think I need to combine my arrays somehow, possibly concat in order to get my final out put of columns.
I've spent a lot of hours trying to figure this out and just looking for some guidance.
Then I need to calculate the commission using sales and the generated number. I'm baffled by this, since I can't just multiply the numbers, I think I need to convert them, but am unsure how. My other BIG problem is how can I get the format to print the Sales, Name, and Commission on each line?
I still need to create a third array that uses sales array and rand commission and since thier not same type I don't know how to convert. Then I think I need to combine my arrays somehow, possibly concat in order to get my final out put of columns.
I've spent a lot of hours trying to figure this out and just looking for some guidance.
You can use the function strtod() to convert string to double.
Founder of :
Lexel Technologies Pte Ltd - SMS (TXT) Marketing software solution
My Blogs: Gooner's Sanctuary
Pet Directory and Forum: FurryTale.net
Lexel Technologies Pte Ltd - SMS (TXT) Marketing software solution
My Blogs: Gooner's Sanctuary
Pet Directory and Forum: FurryTale.net
•
•
Join Date: Aug 2008
Posts: 16
Reputation:
Solved Threads: 1
k
The rest I still have to think about but for outputing
NB blah stands for what ever other data you need to output
The rest I still have to think about but for outputing
C++ Syntax (Toggle Plain Text)
cout<<"commision\t"<<"blah\t"<<"blah"<<endl; for(int n=0;n<blah;n++) { cout<<commision<<"\t"<<blah<<"\t"<<blah<<endl; }
Last edited by Tekmaven; Oct 4th, 2008 at 6:59 pm. Reason: Code tags
![]() |
Similar Threads
- character arrays...help please!!! (C++)
- Concatenation of strings without string.h (C++)
- I lack focus... (Java)
Other Threads in the C++ Forum
- Previous Thread: pls help!!!!!!! round robin algortihm
- Next Thread: Count sequence in char array
Views: 1105 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





