Hi all I am new to c++ as I am taking a entry level class. We have to write a program using ohm's law. The program uses arrays (possibly pointers) and has to use a data file that is given to us. The data file includes values for current and resistance. i know the math behind this program, but I am completely lost on how to get started and how to use a data file. Any help would be much appreciated. I know you don't want to do my homework I just can't find any examples online.
This is my code so far I know it is not much, but I cannot seem to figure out how to limit the user to inputting ten values for current and 10 for resistance. I also cant figure out how to get the code to run the inputted values. Anyways here is what I have:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile("test.dat");
cout << "Enter current and resistance." << endl;
cout << "Press ctrl+z after inputting 10 values for current and resistance \n" << endl;
double current;
double resistance;
double voltage;
while( cin>> current >> resistance) {
myfile << current <<' '<< resistance << endl;
}
ifstream file ("test.dat");
while( file >> current >> resistance) {
voltage = current * resistance;
cout << voltage << "\t" << current << "\t" << resistance<< endl;
}
}
This is my code so far I know it is not much, but I cannot seem to figure out how to limit the user to inputting ten values for current and 10 for resistance. I also cant figure out how to get the code to run the inputted values. Anyways here is what I have:
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile("test.dat");
cout << "Enter current and resistance." << endl;
cout << "Press ctrl+z after inputting 10 values for current and resistance \n" << endl;
double current;
double resistance;
double voltage;
while( cin>> current >> resistance) {
myfile << current <<' '<< resistance << endl;
}
ifstream file ("test.dat");
while( file >> current >> resistance) {
voltage = current * resistance;
cout << voltage << "\t" << current << "\t" << resistance<< endl;
}
}
Here is what I have so far. I cannot seem to figure out how to limit the user input to 10 values for current and resistance and I don't know how to get this data to run in the rest of the program.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream myfile("test.dat");
cout << "Enter current and resistance." << endl;
cout << "Press ctrl+z after inputting 10 values for current and resistance \n" << endl;
double current;
double resistance;
double voltage;
while( cin>> current >> resistance) {
myfile << current <<' '<< resistance << endl;
}
ifstream file ("test.dat");
while( file >> current >> resistance) {
voltage = current * resistance;
cout << voltage << "\t" << current << "\t" << resistance<< endl;
}
}