creating an inFile

Write a C++ program to calculate boarding bills for a kennel. The cost per day is determined by the weight of the dog according to the following chart:
Weight < 10 pounds $ 8.00 per day

10 <=Weight < 30 $12.00 per day

30 <=Weight < 50 $18.00 per day

Weight >=50 pounds $ 22.00 per day

A text file has information about the dogs that are boarding at the kennel. Each line contains the following information for one dog:
the last name of the dog’s owner, the dog’s weight , the number of days the dog is staying at the kennel. The three data items are separated by blank spaces. The two numbers are both integers.

output should contain:


Four labeled columns of information about the dogs in the file
Dog owner dog weight number of days total cost

A counter of the total number of dogs processed.
A count of dogs in each category.
The total amount of money collected for all dogs in the file.

Money should have 2 decimal places and a dollar sign.



here is the txt file

Smith 50 5
Jones 70 5
Hacker 42 3
Henson 10 8
Byrd 30 1
Jarman 25 10
Shaffer 12 7
Klaus 6 3



can someone lead me in the right direction. all i want to do is print out the information from the text file . if you can help me i would appreciate it greatly. im studying for my lab final. this is just a practice for lab final. i wont be turning this in, so its not hw. i need a head start on the code

thank you
Last edited on
something like this (untested)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
char* filename;
std::ifstream file;

file.open(filename, std::ios::in);
if (!file.is_open()) {
	printf("Error opening or finding file with filename '%s'.", filename);
	exit(1);
}

string line, name;
int weight, days;
while (getline(file,line)) {
	file >> name; 
	file >> weight;
	file >> days;
	printf("%s %i %i", name, weight, days);
}

file.close();
thank you
here's what i have

#include <iostream>
#include <fstream>
#include <string>



using namespace std;

char* filename;
std::ifstream file;

int main ()
{




file.open("a.txt", std::ios::in);
if (!file.is_open()) {
printf("Error opening or finding file with filename '%s'.", "a.txt");
exit(1);
}

string line, name;
int weight, days;
while (getline(file,line)) {
file >> name;
file >> weight;
file >> days;
printf("%s %i %i", name, weight, days);
}

file.close();


system ("pause" );
return 0;
}



here is an error i get

30 C:\Users\name\Desktop\prj5\Untitled5.cpp [Warning] cannot pass objects of non-POD type `struct std::string' through `...'; call will abort at runtime
Try changing 'string line, name;' to 'char *line; char *name;'
Topic archived. No new replies allowed.