Skip to content

Instantly share code, notes, and snippets.

@andraantariksa
Created April 1, 2019 13:06
Show Gist options
  • Save andraantariksa/6dcfe3b396709f2b43c980fe37b49b3f to your computer and use it in GitHub Desktop.
Save andraantariksa/6dcfe3b396709f2b43c980fe37b49b3f to your computer and use it in GitHub Desktop.
#include <iostream>
#include <iomanip>
#include <fstream>
typedef unsigned short u16;
struct student {
std::string id;
u16 score1;
u16 score2;
u16 score3;
};
int main(){
std::ofstream file;
file.open("output.txt");
student array_of_student[3];
for(u16 i = 0; i < 3; i++){
std::cout<<"ID of the student number "<<i+1<<"?\n";
std::cin>>array_of_student[i].id;
std::cout<<"The 1st score of the student number "<<i+1<<"?\n";
std::cin>>array_of_student[i].score1;
std::cout<<"The 2nd score of the student number "<<i+1<<"?\n";
std::cin>>array_of_student[i].score2;
std::cout<<"The 3rd score of the student number "<<i+1<<"?\n";
std::cin>>array_of_student[i].score3;
}
file<<std::left<<std::fixed;
file<<std::setw(13)<<"ID Number"<<std::setw(10)<<"Score 1"<<std::setw(10)<<"Score 2"<<std::setw(10)<<"Score 3"<<"Avg\n";
for(u16 i = 0; i < 3; i++){
file<<std::setw(13)<<array_of_student[i].id<<std::setw(10)<<array_of_student[i].score1<<std::setw(10)<<array_of_student[i].score2<<std::setw(10)<<array_of_student[i].score3<<std::setw(10)<<(array_of_student[i].score1+array_of_student[i].score2+array_of_student[i].score3/3)<<"\n";
}
file.close();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment