What's new

Closed Need help optimizing your program code? pasok!

Status
Not open for further replies.
pano mag comment ng codes na napapaikli siya para di mahaba yung comment ko pano siya tinatype papakita ko lang ginawa ko paps
 
sige paps hehe. pano icomment yung codes paps para di siya mahaba di ba may tinatype dun para mapakita ko sayo tapos ask ko na din pano ko siya gagawan ng goto para bumabalik siya
 
sige paps hehe. pano icomment yung codes paps para di siya mahaba di ba may tinatype dun para mapakita ko sayo tapos ask ko na din pano ko siya gagawan ng goto para bumabalik siya
Click mo lang yung "+" sign tapos lagay mo sa code tag.
Gamit ka nalang ng while loop para sa goto. Hindi uso ang goto sa c++.
Assembly Language pwede pa.
 
eto sir para umuulit sana siya
Code:
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sstream>
using namespace std;

int main()
{
    string cinema[9][6] =
    {
        {"Cinema 1", "A", "Avengers Infinity War [PG]", "200", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 1", "B", "Ant Man [PG]", "230", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 1", "C", "Rampage [PG]", "250", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 2", "A", "The How's of Us [G]", "210", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 2", "B", "How I Met Your Mother [PG]", "220", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 2", "C", "Fifty Shades [SPG]", "215", "6:30pm - 8:30pm", "8:30pm - 10:30pm"},
        {"Cinema 3", "A", "The Nun [SPG]", "220", "10:30am - 12:30pm", "12:30pm - 2:30pm"},
        {"Cinema 3", "B", "Anabelle [SPG]", "225", "2:30pm - 4:30pm", "4:30pm - 6:30pm"},
        {"Cinema 3", "C", "The Purge [SPG]", "190", "6:30pm - 8:30pm", "8:30pm - 10:30pm"}
    };

    int cinemaIndex = 1;
    string cinemaInput;
    string movieInput;
    string timeInput;
    int seatInput;
    bool successPicking = false;
    float total = 0;
    string currentCinemaIndex =cinema[0][0];

    dito:
    cout << "<<<<<<[Welcome to World Cinema]>>>>>>\n";
    cout << "Cinema List:\n";
    cout << "======================================\n";
    cout << cinema[0][0] << ":\n";


    //Show the môvięs in each cinema

    for(int i = 0; i < 9; i++)
    {
        if(currentCinemaIndex != cinema[i][0])
        {
            currentCinemaIndex = cinema[i][0];
            cout<< "======================================\n";
            cout<< cinema[i][0] << ":\n";
        }

        cout<< "[" << cinema[i][1] << "] " << cinema[i][2] << "\n";
    }

    //Pick what cinema
    cout<< "\n\nSelect cinema [1|2|3]: ";
    cin >> cinemaInput;
    cinemaInput = "Cinema " + cinemaInput;

    if (cinemaInput == "0")
    {
        goto dito;
    }

    else
    {
        
        cout<< "Select what movie [A|B|C]: ";
        cin >> movieInput;
    }

    cout<< "======================================\n";
    cout<< "Selected:\n\n";

    //Search the picked cinema and môvię then output in the screen
    for(int i = 0; i < 9; i++)
    {
        if(cinema[i][0] == cinemaInput && cinema[i][1] == movieInput)
        {
            cout<< cinema[i][2] << "\n";
            cout<< "Price: P " << cinema[i][3] << "\n";
            cout<< "Time Available: \n";
            cout<< "[1]" << cinema[i][4] << "\n";
            cout<< "[2]" << cinema[i][5] << "\n";
            cout<< "[3]" << "CANCEL\n\n";

            while (true)
            {
                cout<< "Select time [1|2]: ";
                cin >> timeInput;

                if(timeInput == "1")
                {
                    timeInput = cinema[i][4];
                    successPicking = true;
                    break;
                }
                else if (timeInput == "2")
                {
                    timeInput = cinema[i][5];
                    successPicking = true;
                    break;
                }
                else if (timeInput == "3")
                {
                    system("cls");
                    break;
                }

                else
                {
                    cout<< "Invalid input, please try again...";
                }
            }
            if(successPicking)
            {
                cout<< "How many seats or tickets: ";
                cin >> seatInput;
                stringstream temp(cinema[i][3]);
                int z=0;
                temp >> z;
                total = z*seatInput;

                cout<< "======================================\n";
                cout<< "movie\n";
                cout<< cinema[i][2] << "\n";
                cout<< "Time: " << timeInput << "\n";
                cout<< "Price: P " << cinema[i][3] << "\n";
                cout<< "Seats: " << seatInput << "\n";
                cout<< "Total: " << total;
            }
            else
            {
                break;
            }
        }
    }
    return 0;
}
 
May possible bang maging function to paps? Yan kasi yung project namen na gawin function yung pinass namin sakanya




#include<iostream>
#include <string>
#include <sstream>
using namespace std;
int main(){
string myString;
int age;
int birthYear;
int birthMonth;
int birthDay;
int currentYear;
int currentMonth;
int currentDay;
int JANUARY =1;
int FEBRUARY = 1;
int MARCH = 1;
int APRIL = 1;
int MAY = 1;
int JUNE = 1;
int JULY =1;
int AUGUST = 1;
int SEPTEMBER = 1;
int OCTOBER = 1;
int NOVEMBER = 1;
int DECEMBER = 1;

cout<< "Enter your birthdate: (i.e Year: 2000 and up Month: 8 Day: 2" << endl;
cout<< "\tYear: ";
getline (cin,myString);
stringstream(myString) >>birthYear;
cout<< "\tMonth: ";
getline (cin, myString);
stringstream(myString) >>birthMonth;
cout<< "\tDay: ";
getline (cin, myString);
stringstream(myString)>> birthDay;
cout<< "\nEnter the current date: (i.e Year: 2018 Month: 12 Day: 1" << endl;
cout<< "\tYear: ";
getline(cin, myString);
stringstream(myString)>> currentYear;

cout<< "\tMonth: ";
getline (cin, myString);
stringstream(myString)>> currentMonth;
cout<< "\tDay: ";
getline(cin, myString);
stringstream(myString)>> currentDay;
age = currentYear - birthYear;
if(currentMonth > birthMonth || (currentMonth == birthMonth && currentDay >= birthDay))
cout <<"\n\nYour age is " << age << endl<< endl;


cout<<" 2018"<<endl;
cout<<"JANUARY"<< endl;
while ( JANUARY <= 31){
cout<<"\t"<< JANUARY;
JANUARY++;
}
cout<< endl <<"FEBRUARY"<< endl;
while (FEBRUARY <= 28){
cout<<"\t"<< FEBRUARY;
FEBRUARY++;
}
cout<< endl<<"MARCH"<< endl;
while (MARCH <= 30){
cout<<"\t"<< MARCH;
MARCH++;
}
cout<<endl<<"APRIL"<< endl;
while ( APRIL <= 30){
cout<<"\t"<< APRIL;
APRIL++;
}
cout<< endl <<"MAY"<< endl;
while (MAY <= 31){
cout<<"\t"<< MAY ;
MAY++;
}
cout<< endl<<"JUNE "<< endl;
while ( JUNE <= 29){
cout<<"\t"<< JUNE ;
JUNE++;
}
cout<< endl<<"JULY"<< endl;
while ( JULY <= 31){
cout<<"\t"<< JULY;
JULY++;
}
cout<< endl<<"AUGUST"<< endl;
while ( AUGUST <= 31){
cout<<"\t"<< AUGUST ;
AUGUST++;
}
cout<< endl<<"SEPTEMBER"<< endl;
while ( SEPTEMBER <= 28){
cout<<"\t"<< SEPTEMBER ;
SEPTEMBER++;
}

cout<< endl<<"OCTOBER"<< endl;
while ( OCTOBER <= 31){
cout<<"\t"<< OCTOBER ;
OCTOBER++;
}
cout<< endl<<"NOVEMBER"<< endl;
while (NOVEMBER <= 30){
cout<<"\t"<< NOVEMBER;
NOVEMBER++;
}
cout<< endl<<"DECEMBER"<< endl;
while (DECEMBER <= 31){
cout<<"\t"<< DECEMBER ;
DECEMBER++;


}
cout<<endl <<" GO TO THE TOP TO SEE YOUR AGE";

}
 
Dikopo kasibgets yung function e paps. Hehe makapasa lang sa finals. Pwedi po pa function? Medyo nahuli napo kasi ako sa mga discussions e. Pero soon mag babasa nako nang mga book
 
Status
Not open for further replies.

Similar threads

Back
Top