C++ :: TXT File - How To Get Each Specific Value And Add Them All Together
Oct 10, 2013
so I wrote this code in class today and I'm almost done but I need to come up with some sort of equation to add up all the total values. The problem is I am reading data off a txt file so it's all being read as one thing. I don't know how to get each specific value and add them all together. This is my code so far.
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;
[Code] .....
here's what's inside the input file
Chisel 50 9.99
Hammer 30 15.99
Nails 2000 0.99
Bolts 200 2.99
Nuts 300 1.99
Soap 55 1.89
I end up multiplying the amount by the price to get the total value as shown in the code above. Now I just don't know how to add the total value of each item to get the total overall value. Also I haven't used invTotal because I want that to be the overall total.
View 1 Replies
ADVERTISEMENT
Mar 5, 2013
How do I make a specific character show up a specific amount of times?
Like I am generating a random number then I need to make "|" show up that many times on the screen.
View 1 Replies
View Related
Oct 10, 2014
I'm trying to open a text file with the name "text.txt", for the purpose of only displaying in the console an specific part of the text file. For example, if I got "This is a test [TEXT] This is the message that should display [/TEXT] this is the end of the file", I want only "This is the message that should display" to be the output, the thing is that I can't imagine anyway of doing that. what I should do?
View 5 Replies
View Related
Mar 12, 2013
I'm trying to add more student information to the specific txt file. I did struct my student information and separated it with an array with max size of 200.
The inside of my current file looks like
Toshi
Aka
Nonal
Donald
The first one represent student[0] and next one is student[1] and so on till student[199]. Right now, only 4 space is occupied, which means the array has information till student[3] but not from student[4] (I guess it has null condition).
What I want to do is, I want to add a new student information to student[4] and till student[199] once at each time.
So, my prompt will look like
Would like to add a new student? Y/N
(if yes goes to below statement and exit if NO)
Hi. Please enter the information of new student. ___________
Student added. Please press any key to continue.
If the key is pressed, it goes back to my initial prompt and continues till I press N.
I sure I'm not using for loop to do this thing, because I'm adding student name one by one.
However, the array is already occupied by other student name till student[3] so, I want to add a new student information to student[4] (I don't want to overwrite the current information). And if student[4] is occupied, then [5] and so on.
View 7 Replies
View Related
Mar 17, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define MAX 200
[Code] ....
Inside of my studentinfo.txt file
Code:
Jnh Has 2353325 23 56 72 34 67 22 46 42 5 23 56 23
Daniel Laurent 6744590 10 20 30 40 50 60 70 80 90 100 40 50
This code is working totally fine. Right now, I'm trying to update a specific data from the student info. Let's say I'm trying to update my student number of Daniel. So, in this case, I want to replace 6744590 to some other student number. I think I have to use fseek() or rewind() and use fputs() but, I don't know how I should decide where to look.
View 8 Replies
View Related
Aug 12, 2014
How would one go about doing this? I am very fond with Windows I/O, but not so much with this subject. I am decent with fstream, probably not as skilled at it as I should be, but I assume <fstream> would be a better choice, since it isn't locked to Windows.
Anyway, say I have a .txt file like this:
Bill is a cow.
Bill likes meat.
Bob is a pig.
Bob and Bill are friends.
And I want to count the number of times "Bill" is written. How would I do that?
View 5 Replies
View Related
Nov 21, 2013
I have a .txt file which contains 121 lines,now I want to read the no 20 columns from that file. How to read it. I have tried the following code.
my c.txt file look like following :
A B C D E.....AAA
#include<stdio.h>
#include "conio.h"
#include "string.h"
int main() {
FILE *fp;
char a2[500];
[Code] ....
View 1 Replies
View Related
Feb 15, 2013
how can i input lines at a specific area in my file. please provide code
View 3 Replies
View Related
Feb 2, 2014
I'm having trouble opening a file from a specific location.
#include "maidcafe.h"
....
char directory[80] = {"C:UsersPublicDocumentsAnime NotesTransaction"};
char code[20];
printf("Enter file name");
gets(code);
strcat(directory,code);
system("start "" %s",directory);
i thought this would work, but it didn't xD. I got an error
View 3 Replies
View Related
Apr 14, 2013
What i try to do is to write a code which reads some specific values from a file and stores them in an array. My File looks like this
Code:
XFOIL Version 6.96
Calculated polar for: Myfoil
1 1 Reynolds number fixed Mach number fixed
xtrf = 1.000 (top) 1.000 (bottom)
Mach = 0.000 Re = 0.200 e 6 Ncrit = 4.000
}
[code]...
View 11 Replies
View Related
Nov 28, 2014
I'm making a binary file that has 100 "empty spaces", and then I want to rewrite specific place with info, however it always writes the info at the end of the file, no matter what I try to get position before I call write() it tells me correct position...
#include <Windows.h>
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
[Code].....
View 5 Replies
View Related
Apr 10, 2014
I am currently working on a small project, which is an ATM simulator but, lately, I've been stuck in a part where I have to overwrite a specific line in a .dat file to update the account's checking and savings balance, once the transaction has been done. I have to use StreamReader and StreamWriter to complete the task and I have also being told to try Collections... which I'm not sure as to why.
Here's my code so far:
private void btnOKd_Click(object sender, EventArgs e) {
int transaction = 0;
atmTIMER.Elapsed += new ElapsedEventHandler(timerRESTART);
FileStream fileTRANSACTIONS = new FileStream("C:\Users\Voyage\Desktop\ATMSim\ATMsim\Transactions.dat", FileMode.Open);
[Code] .....
View 14 Replies
View Related
Feb 6, 2014
Some codes to delete a text in a specific line in a text file.
Example:
This is line 1
This is line 2
this is line 3
Removing line 2,
This is line 1
This is line 3
//////////////////
View 2 Replies
View Related
Jul 23, 2014
I wrote a code to read a specific amount of data from file until terminating set is reached. however the code does what its supposed to correctly until it reaches the 5th loop it justs stops responding. I've checked the reading file and all elements are correct in the file.
Code:
int main(void){
FILE *file1;
FILE *file2;
FILE *file3;
struct t test1;
struct t test2;
[Code] ....
Screenshot of program crashing:
Screenshot of reading file:
View 11 Replies
View Related
May 29, 2014
I want to select three columns from my text file i.e. Empl No, Start Date and Created Date. After selecting this, I want to insert the data into a database.
I have attached a copy of the text file.
I have the following code so far:
if (File.Exists(filename))
{
string[] lines = File.ReadAllLines(filename);
for (int y = 0; y < lines.Length; y++) {
Console.WriteLine(lines[y].ToString());
}
How do i select specific details for each employee
View 1 Replies
View Related
Oct 15, 2013
I am trying to print a specific line from a textfile
e.g
I have a text file called info.txt and inside it contains the id,item name, price, quantity
Code:
1,shirt,100,10
2,pants,50,9
3,pen,20,8
I know how to find a specific word at the line in the file but how do I find and print out the specific line e.g(print out just the entire contents of line 2)?
Code:
string temDescription;
ofstream fout;
int curLine = 0;
[Code].....
View 1 Replies
View Related
Feb 13, 2013
I am suppose to make a program that will output a line for a specific age group,but everytime I execute the exe file it gives me the desired line and also the last line included everytime.Where did I go wrong with it including the last line everytime?
#include <iostream>
using namespace std;
int main() {
double age;
cout<<"Enter your age:";
cin>>age;
if (0<age && age <6)
[Code] ......
View 1 Replies
View Related
Aug 30, 2013
I have a huge text file in following format:
{Bunch of text
.
.
}
[Code].....
I want to extract Text1, Text2, Text3, Text4,..., Text600 in the output file. How can i achieve this?
/* BTW, I am not getting my homework done here. I am an ex-programmer, who has now moved to marketing for some time now, and today, I encountered this problem, which I believe can be solved easily through programming. */
View 3 Replies
View Related
Aug 2, 2014
I have a text file called (Test.txt) with the following text:
This is line one
This is line two
This is line three
How do I go about writing a program that will print a line of text (e.g. "This in line two" on the console screen?
All I can seem to do is display the entire text file.
View 6 Replies
View Related
Jun 8, 2014
How do I return a specific value from a function in order for me to cout it in my int main?
In this case i have solved for a value sigma1 in my function but i want to use the value of sigma1 in my int main also and in other places so how would i do that?
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
[Code].....
View 5 Replies
View Related
May 5, 2014
Basically I am creating a game and I need the ai to look for specific buttons. At the moment this is the code I have, and what it does is it makes the ai look for any random button that has't already been clicked.
Code:
private Button look_for_spaces() {
Console.WriteLine("Looking for spaces");
Button b = null;
foreach (Control c in Controls) {
b = c as Button; // performs a cast
[Code] .....
Now what I'm trying to do is make the ai go through 4 searches in steps instead of looking for any button. I want it first to look for buttons 1, 2 and 3, if there's a space in any then it will be clicked but if all of them are already clicked it will look for spaces in buttons 4, 5 and 6 and so on if that makes sense. But i'm not too sure how I would do it.
View 3 Replies
View Related
Dec 13, 2014
I created a program that will create a file and print a list on it. Here is the code for my program:
Code:
int controlvalue(void) {FILE *controlvalue;
controlvalue = fopen("something.txt", "a+");
/* Series of fprintfs */
fclose (controlvalue);
return 1;}
Here is an example list created by my program:
Code:
[Gifts]Candy=45
Chocolate=32
Toy=128
Robot=754
Doll=1492
Star=21
Phone=72
Skateboard=87
Frame=314
Days=365
Perfume=421
I want to get the value of "Skateboard" on file. So I need to read 9 lines. On the 9th line, the gets() loop will stop. But, what if I only want to get the value of "Skateboard" as integer (87) and not a string? Also, is it possible to scan the value of Skateboard if it's located on a different (or unknown) line?
View 1 Replies
View Related
Jan 12, 2015
I want to access specific lines in a "*.txt" file. I've heard of seekp() and what not, but don't know how to call them as such.
View 6 Replies
View Related
Mar 16, 2015
im having trouble with a function im writing. Its supposed to find the minimum value in an array and return the location of that value heres what i have so far :
int findLowest (int numb []) {
// findLow will hold the subscript of the lowest value in the array
int findLow = numb[0];
int x;
for (x = 0; x < 5; x++){
if (numb[x] < findLow)
findLow = x;
}
return findLow;
}
View 3 Replies
View Related
Apr 26, 2015
I want to replace what is in a specific sector with value inside a buffer(dummy value). This code will read what is inside a specific sector. To make sure it works it display what is inside the sector and it displays the chosen dummy value. (the two cout's in main)
What I want to do is to replace the dummy value with what is inside the specific sector. So if the dummy value is '0', I want to replace what is in sector 285 with '0'.
#include <windows.h>
#include <stdio.h>
#include <iostream>
#include <iomanip>
using namespace std;
#define FILE_SHARE_VALID_FLAGS 0x00000007
#define BUFFER_SIZE 512
[Code] ....
View 1 Replies
View Related
Nov 26, 2014
Here's my list code:
Color.FromArgb(alfa, 0, 255, 255),
Color.FromArgb(alfa, 0, 255, 0),
Color.FromArgb(alfa, 64, 255, 0),
Color.FromArgb(alfa, 128, 255, 0),
Color.FromArgb(alfa, 192, 255, 0),
Color.FromArgb(alfa, 255, 255, 0),
Color.FromArgb(alfa, 255, 192, 0),
Color.FromArgb(alfa, 255, 128, 0),
Color.FromArgb(alfa, 255, 64, 0),
Color.FromArgb(alfa, 255, 0, 0)
How can I get a specific element value from that list?
For example:
if(true)
{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}
I don't see the "Edit" option and I've noticed a slight error in the previous post.There should be, obviously, [code]if(true)
{
//get "192" from Color.FromArgb(alfa, 255, 192, 0)
}
I was missing the closing tag.
View 2 Replies
View Related