Need Help with my code please

my code works but now i need to make it so it use pointers in order to call in the values rather then the array that i have it working with. Another thing I am trying to figure out how to do is create and output.dat file in order to output it rather than just making it output as a regular code. Basically the code is for calculating voltage that comes from data that is pulled in regarding a table of current and resistance. It is supposed to output the full table of voltage, current and resistance.


#include <iostream>
#include <iomanip>
#include <string>
#include <stdlib.h>
#include <fstream>

using namespace std;

double v[10]; //v is the voltage array of 10
double value[10][2];

void create(ifstream& importfile);
void calculate();
void print();

int main()
{
ifstream importfile("test.dat");
create(importfile);
calculate();
print();

return 0;
}

void create(ifstream& importfile)
{
char tempvalue[10];
for(int x = 0; x < 10; x++)
{
importfile.get(tempvalue, 10, '\t');
value[x][0] = atof(tempvalue); //array to function

importfile.get(tempvalue, 10, '\n');
value[x][1] = atof(tempvalue);
}
}

void calculate()
{
for(int x = 0; x < 10; x++)
{
v[x] = value[x][0] * value[x][1];
}
}

void print()
{
cout << "Voltage" << setw(10) << "Current" << setw(13) << "Resistance" << endl;

for(int x = 0; x < 10; x++)
{
cout << fixed << setprecision(4);
cout << v[x] << setw(10) << value[x][0] << setw(10) << value[x][1] <<endl;
}
}

Topic archived. No new replies allowed.