What's new

Closed Need help optimizing your program code? pasok!

Status
Not open for further replies.
Bale last prefinal namin us nagprigram kame ng trïânglê. Idetirmine po if anong kindss of trïânglês. Bale decisions sir? Yung if, else if, if. Yan sir yung yopic namin. Tbh, ngayong final lng ako nagkalaman sa programing. Hahaha the combination of analyzing and combination of tutorials sa google. Pero if di makaya yun nag tataning ako sa inyo. Hehe
Well, start learning using the code na nabigay ko sayo. Kasi mostly basics lang yun.
If-else, array, for-loop. Yun yung mga main topic ng content nung code.
Yung iba basic, output input.
 
Ask lang po ako how to open a text file sa Java? Puro path po sa computer nasesearch ko. Android Java N-IDE po gamit ko cp lang.
 
Pero madalang po kami mag laboratory kaya sa Phone po ako nagpapraktis
Kung programmer or IT student ka, give yourself a laptop kahit yung pinakamura. Mas mahahasa ka. Sa companies hindi sa phone kayo nakaharap. Saka maraming wala sa phone ang magagawa sa laptop lalo na kung big projects.
Kung ganito kaliit okay pa.
 
Paps pano mafix yan?

#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main(){
int age;
int birth_year;
int birth_month;
int birth_date;
int current_year;
int current_month;
int current_date;
string current_date, current_month, current_year;
string birth_date, birth_month, birth_year;


cout<<"enter you birthdate - date/month/year"
getline(birth_date, birth_month, birth_year);
streamstring(cin, birth_date,birth_month,birth_year)>>irth_date>>birth_month>>birth_year;
getline(current_date, current_month, current_year);
streamstring(cin, current_date,current_month,current_year)>>current_date>>current_month>>current_year;

age = current_year - birth_year;
if(current_date<birth_date)
age++;
else{
if (current_month<birth_month)
age++;

cout <<"your age is " << age << endl<< endl;
}
 
Paps pano mafix yan?

#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main(){
int age;
int birth_year;
int birth_month;
int birth_date;
int current_year;
int current_month;
int current_date;
string current_date, current_month, current_year;
string birth_date, birth_month, birth_year;


cout<<"enter you birthdate - date/month/year"
getline(birth_date, birth_month, birth_year);
streamstring(cin, birth_date,birth_month,birth_year)>>irth_date>>birth_month>>birth_year;
getline(current_date, current_month, current_year);
streamstring(cin, current_date,current_month,current_year)>>current_date>>current_month>>current_year;

age = current_year - birth_year;
if(current_date<birth_date)
age++;
else{
if (current_month<birth_month)
age++;

cout <<"your age is " << age << endl<< endl;
}
Hindi pwede maulit variable name. May current_date ka na na int tapos may string din.
 
Paps pano mafix yan?

#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main(){
int age;
int birth_year;
int birth_month;
int birth_date;
int current_year;
int current_month;
int current_date;
string current_date, current_month, current_year;
string birth_date, birth_month, birth_year;


cout<<"enter you birthdate - date/month/year"
getline(birth_date, birth_month, birth_year);
streamstring(cin, birth_date,birth_month,birth_year)>>irth_date>>birth_month>>birth_year;
getline(current_date, current_month, current_year);
streamstring(cin, current_date,current_month,current_year)>>current_date>>current_month>>current_year;

age = current_year - birth_year;
if(current_date<birth_date)
age++;
else{
if (current_month<birth_month)
age++;

cout <<"your age is " << age << endl<< endl;
}
Mas simple. Hindi gagamit ng string.

Code:
#include<iostream>

using namespace std;

int main(){
    int age;
    int birthYear;
    int birthMonth;
    int birthDay;
    int currentYear;
    int currentMonth;
    int currentDay;

    cout<< "Enter your birthdate: (i.e Year: 1994 Month: 8 Day: 2" << endl;
    cout<< "\tYear: ";
    cin >> birthYear;
    cout<< "\tMonth: ";
    cin >> birthMonth;
    cout<< "\tDay: ";
    cin >> birthDay;
    cout<< "\nEnter the current date: (i.e Year: 2018 Month: 12 Day: 1" << endl;
    cout<< "\tYear: ";
    cin >> currentYear;
    cout<< "\tMonth: ";
    cin >> currentMonth;
    cout<< "\tDay: ";
    cin >> currentDay;

    age = currentYear - birthYear;

    if(currentMonth > birthMonth || (currentMonth == birthMonth && currentDay >= birthDay))
    {
        age++;
    }

    cout <<"\n\nYour age is " << age << endl<< endl;
    
    return 0;
}
 
Mas simple. Hindi gagamit ng string.

Code:
#include<iostream>

using namespace std;

int main(){
    int age;
    int birthYear;
    int birthMonth;
    int birthDay;
    int currentYear;
    int currentMonth;
    int currentDay;

    cout<< "Enter your birthdate: (i.e Year: 1994 Month: 8 Day: 2" << endl;
    cout<< "\tYear: ";
    cin >> birthYear;
    cout<< "\tMonth: ";
    cin >> birthMonth;
    cout<< "\tDay: ";
    cin >> birthDay;
    cout<< "\nEnter the current date: (i.e Year: 2018 Month: 12 Day: 1" << endl;
    cout<< "\tYear: ";
    cin >> currentYear;
    cout<< "\tMonth: ";
    cin >> currentMonth;
    cout<< "\tDay: ";
    cin >> currentDay;

    age = currentYear - birthYear;

    if(currentMonth > birthMonth || (currentMonth == birthMonth && currentDay >= birthDay))
    {
        age++;
    }

    cout <<"\n\nYour age is " << age << endl<< endl;
   
    return 0;
}
Thanks for helping again and again paps.
 
mrHazan , eto po yung code mo kinopya ko lang pero may error po sakin di ko po alam pano idebug e pahelp po sir para mapagaralan ko po thanks.
upload_2018-10-17_2-0-12.png
 

Attachments

Paps anong magandang gamitin para sa looping? Example: binary to decimal, exponential, Fibonacci.
Need kolang po sa school he he.
Nakuha napo young mga example nayan kaya bawal parepareho.
 
Paps anong magandang gamitin para sa looping? Example: binary to decimal, exponential, Fibonacci.
Need kolang po sa school he he.
Nakuha napo young mga example nayan kaya bawal parepareho.
Depende. Parehas lang naman kasi ang while loop at for loop. Kung saan ka mas magaling yun gamitin mo.
 
Status
Not open for further replies.
Back
Top