Sunday, July 12, 2015

Year Level Checker Using Pointers in C++

This sample program will determine the year level of the student using pointers in C++. The code is very simple to understand and follow.

Feel free to use my code in your programming projects at school or work.  If you have some questions please send me an email at jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

People here in the Philippines can reach me at my mobile number 09173084360.

Thank you very much and Happy Programming.



Program Listing


#include <iostream>

using namespace std;



main ( )
{

struct  {

int year_level;

}*ptr;

cout << "Enter year level :=> ";
cin >> ptr->year_level ;
cout << "\n\n";


if (ptr-> year_level == 1) {
    cout << "You are a Freshmen";
}
else if (ptr-> year_level == 2) {
    cout << "You are a Sophomore";
}
else if (ptr-> year_level == 3) {
    cout << "You are a Junior";
}
else if (ptr-> year_level == 4)
  {
    cout << "You are a Senior";
}
else {
    cout << "Invalid Option Try Again";
}
cout << "\n\n";
system("pause");
}

No comments:

Post a Comment