In: Computer Science
In C++ Write a program to store exam scores into a file. The program will ask the user how many exam scores to enter. Then it will ask the user for each exam score and store them in a file called scores.dat The file output should have the following format: Exam 1: 97 Exam 2: 85
****This requires some effort so please drop a like if you are satisfied with the solution****
I have satisfied all the requirements of the question and I'm providing the screenshots of code , output and file output for your reference...
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main(){
ofstream file;
file.open("C://Users/THE__INFINITY/Desktop/scores.dat");
cout<<"Enter how many exam scores to enter:
";
int n,score,i=1;
cin>>n;
while(n--){
cout<<"Enter exam
"<<i<<" score: ";
cin>>score;
file<<"Exam
"<<i<<": "<<score<<" ";
i++;
}
file.close();
return 0;
}
Output Screenshot:
File output after execution:
Code Screenshot: