76.6k views
0 votes
Write a function that reads from a file the name and the weight of each person in pounds and calculates the equivalent weight in kilograms. Output the Name, weightLB, and weightKG in that order. Format your output to two decimal places. (1 kilogram

User Jwngr
by
4.9k points

1 Answer

4 votes

Answer:

#include <iostream>

#include <fstream>

#include <iomanip>

using namespace std;

int main(){

string name;

double weightKg, weightPd;

cout<< fixed << setprecision(2);

fstream myFile("filename.txt");

while (getline( myFlie, name, weightPd)){

weightKg = weight * 0.453592;

cout<< name << weightPd <<weightKg;

}

myFile.close();

}

Step-by-step explanation:

The C++ source code reads in the content of a file that has a name and weight value in pounds and outputs the name, weight in pounds and the weight in kilograms.

User Nat Aes
by
4.7k points