Hi, I was wondering if it would be possible to get some help. I'm making a program for my chemistry course that requires a number of values to be read from a text file, a calculation done with those values, and the new numbers then printed onto the screen and saved into a file.
So far I have the following code,
I tried making an integer variable b which was equal to a*2 however this didn't seem to work, and instead I got an error message.Code://A program that calculates the reduced mass of diatomic molecules. //The following libraries will be used. #include <stdio.h> #include <stdlib.h> #include <math.h> using namespace std; int main() { int selection,b;//Defines the selection variable to determine the input. printf("A program that works out the reduced mass of diatomic molecules.\n\n");//Prints the introductory message. printf("Would you like to input the data from the keyboard or a .txt file?\n");//Allows the user to choose the input. printf("1. From a .txt file "); printf("2. From the keyboard\n"); printf(":"); scanf("%d",&selection);//Assigns the value of the selection int variable. FILE *FP; char a[100]; printf("Please input a filename including the .txt extension:"); scanf("%s",a); FP = fopen(a,"r"); if (FP==NULL) { printf("Error Reading File"); } while (!feof(FP)) { fgets(a,100,FP); printf("%s",a); } fclose(FP); return 0; }
How can I perform a calculation on the numbers as they are read from the text file?