Untitled

 avatar
unknown
c_cpp
4 years ago
955 B
7
Indexable
#include <string> // to use string datatype
#include <iostream>

using namespace std; // so we won't have to specify that we'll be using the std anymore when using the members of this namespace (e.g. no more std::cout)

int main() {
    // declaring variables
    float prelimGrade,midtermGrade,finalGrade,average;
    string name;
    
    // input/output
    cout << "input name: ";
    cin >> name;
    cout << "input prelim grade: ";
    cin >> prelimGrade;
    cout << "input midterm grade: ";
    cin >> midtermGrade;
    cout << "input final grade: ";
    cin >> finalGrade;
    
    // average calculation
    average=(prelimGrade+midtermGrade+finalGrade)/3;
    cout << "Hello " << name << ", your average is " << average << endl;
    
    // using ternary operator for conditional statement | condition ? true : false 
    average > 75 ? cout<< "Congrats, you passed!": cout << "Sorry, you failed!";
    
    // success execution
    return 0;
}
Editor is loading...