Skip to content

Instantly share code, notes, and snippets.

@vignesh0025-zz
Last active August 29, 2015 14:24
Show Gist options
  • Save vignesh0025-zz/e36289ef5ba4c6c9e933 to your computer and use it in GitHub Desktop.
Save vignesh0025-zz/e36289ef5ba4c6c9e933 to your computer and use it in GitHub Desktop.
CGPA Calculator
//
// main.cpp
// Home
//
// Created by Vignesh on 04/07/15.
// Copyright (c) 2015 Vignesh. All rights reserved.
// Copyright (c) 2015 XCode, Apple Corporation
//
#include <iostream>
#include <stdlib.h>
#include <iomanip>
using namespace std;
int main(int argc, const char * argv[]) {
cout << "CGPA Calculator" << endl;
const float credit[6] = {23.00f,22.00f,22.00f,22.00f,22.00f,22.00f};
float gpa[6],cgpa,num,denom;
cout.precision(2);
cout.setf(ios::fixed);
for (int i = 0;i < 6; i++)
{
cout << "Enter GPA of Sem " << i+1 << ":";
cin >> gpa[i];
}
cout<<endl;
cout << "_____________________________________" << endl;
cout << "|Semester No |" << " Result |" << endl;
cout << "|___________________________________|" << endl;
cout << "| "<<1<<" |"<<" "<< 0<<" |"<< endl;
for (int i =1 ; i < 6 ; i++)
{
num = 0.00f; denom = 0.00f;
for (int j = 0; j <= i; j++) {
num += (float)(gpa[j]* credit[j]);
denom += (float)credit[j];
if(j == i){
cgpa = (float)(num/denom);
cout << "|___________________________________|" << endl;
cout << "| "<<i+1<<" |"<<" "<< cgpa <<" |"<< endl;
}
}
}
cout << "|___________________________________|" << endl;
return 0;
}
@vignesh0025-zz
Copy link
Author

Updated Man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment