program looping dan deret bilang dengan c++

Program Looping dan Deret bilangan dengan c++

Berikut adalah Program Looping dan Deret bilangan dengan menggunakan c++

C++
#include <iostream>
#include <stdlib.h>
#include <conio.h>
using namespace std;
main()
{
    a:
    int menu;

    cout<<"                Menu Pilihan"<<endl;
    cout<<"==========================================="<<endl;
    cout<<"1. Nested If 1"<<endl;
    cout<<"2. Bilangan Prima 2"<<endl;
    cout<<"3. Switch Case 3"<<endl;
    cout<<"4. Deret Kuadrat 4"<<endl;
    cout<<"5. Looping String 5"<<endl;
    cout<<"Masukan Menu Pilihan Anda = ";
    cin>>menu;
    cout<<endl;
    switch (menu)
    {
    case 1:
        int Mid,Final,Assigment;
        cout<<"Input Mid Test Score = \n";
        cin>>Mid;
        //cout<<Mid;

        cout<<"Input Final Test Score = \n";
        cin>>Final;
        //cout<<Final;

        cout<<"Input Assigment Score = \n";
        cin>>Assigment;
        //cout<<Assigment;

        int NA;
        NA = (Mid*0.3) + (Final*0.3) + (Assigment*0.4);
        cout<<"Final Score = "<<NA<<endl;

        if (NA >=65)
        {
            cout<<endl<<"===============================You Pass The Test================================\n";
        }
        else
        {
            cout<<endl<<"===============================You Didn't Pass The Test=========================\n";
        }


        if (NA >=89)
        {
            cout<<"Your Grade Is = A"<<endl<<"Very Good"<<endl;
        }
        else if (NA >=70)
        {
            cout<<"Your Grade Is = B"<<endl<<"Good"<<endl;
        }
        else if (NA >=60)
        {
            cout<<"Your Grade Is = C"<<endl<<"Pretty Good"<<endl;
        }
        else if (NA >=50)
        {
            cout<<"Your Grade Is = D"<<endl<<"Not Good Enough"<<endl;
        }
        else if (NA >=20)
        {
            cout<<"Your Grade Is = E"<<endl<<"Poorly"<<endl;
        }
        cout<<endl;
        cout<<endl;
        int choice;
        b:

        cout<<"                    ***Information***"<<endl;
        cout<<"============================================================="<<endl;
        cout<<"1. Back To Menu"<<endl;
        cout<<"2. Clear Screen"<<endl;
        cout<<"Pilihan Anda [1/2] = "<<endl;
        cin>>choice;
        switch (choice)
        {
        case 1:
            goto a;
            break;
        case 2:
            system ("csl");
            break;
        default:
            goto b;
            break;
        }
        break;
    case 2:
        int masuk, x, prime;
        cout<<"Masukan Angka = ";
        cin>>masuk;
        prime=0;
        for (x=1;x<=masuk;x++)
        {
            if (masuk%x==0)
            {
                prime++;
            }
        }
        if (prime == 2)
            cout<<masuk<<"Adalah Bilangan Prima"<<endl;
        else
            cout<<masuk<<"Adalah Bukan Bilangan Prima"<<endl;

        cout<<endl;
        cout<<"                    ***Information***"<<endl;
        cout<<"============================================================="<<endl;
        cout<<"1. Back To Menu"<<endl;
        cout<<"2. Clear Screen"<<endl;
        cout<<"Pilihan Anda [1/2] = "<<endl;
        cin>>choice;
        switch (choice)
        {
        case 1:
            goto a;
            break;
        case 2:
            system ("csl");
            break;
        default:
            goto b;
            break;
        }
        break;
    case 3:
        long int pesanan, juice, soft_drink, milk_shake, tiramisu, cookies_cream, quantity, discount, price, pay, total;
        menu:
        cout<<"************FRESH************"<<endl;
        cout<<"1. Juice"<<endl;
        cout<<"2. Soft Drink"<<endl;
        cout<<"3. Milk Shake"<<endl;
        cout<<"4. Tiramisu"<<endl;
        cout<<"5. Cookies Cream"<<endl;
        cout<<endl;
        cout<<"Masukan Nomer Pesanan Anda [1/2/3/4/5] = ";
        cin>>pesanan;
        cout<<endl;
        switch (pesanan)
        {
        case 1:
            price = 100000;
            cout<<"Pilihan Pesanan Anda = Juice"<<endl;
            break;
        case 2:
            cout<<"Pilihan Pesanan Anda = Soft Drink"<<endl;
            price = 15000;
            break;
        case 3:
            cout<<"Pilihan Pesanan Anda = Milk Shake"<<endl;
            price = 20000;
            break;
        case 4:
            cout<<"Pilihan Pesanan Anda = Tiramisu"<<endl;
            price = 18000;
            break;
        case 5:
            cout<<"Pilihan Pesanan Anda = Cookies Cream"<<endl;
            price = 16000;
            break;
        default:
            cout<<"Pilihan Ada Lima"<<endl;
            goto menu;
            break;
        }
        cout<<endl;
        cout<<"Quantity = ";
        cin>>quantity;
        total = quantity*price;
        if (quantity >=2)
        {
            discount = (total*0.1);
        }
        else
        {
            discount = 0;
        }
        pay = total-discount;
        cout<<"Total = "<<total<<endl;
        cout<<"Discount = "<<discount<<endl;
        cout<<"Pay = "<<pay<<" ("<<total<<"-"<<discount<<") "<<endl;
        cout<<"=========================================================="<<endl;
        cout<<endl;
        cout<<"                    ***Information***"<<endl;
        cout<<"============================================================="<<endl;
        cout<<"1. Back To Menu"<<endl;
        cout<<"2. Clear Screen"<<endl;
        cout<<"Pilihan Anda [1/2] = "<<endl;
        cin>>choice;
        switch (choice)
        {
        case 1:
            goto a;
            break;
        case 2:
            system ("csl");
            break;
        default:
            goto b;
            break;
        }
    case 4:
        int z, a, hasil;
        cout<<"Masukan Angka = ";
        cin>>z;
        cout<<endl;
        a=1;
        while (a<=z)
        {
            hasil = a*a;
            cout<<" "<<hasil;
            a++;
        }
        cout<<endl;
        cout<<"                    ***Information***"<<endl;
        cout<<"============================================================="<<endl;
        cout<<"1. Back To Menu"<<endl;
        cout<<"2. Clear Screen"<<endl;
        cout<<"Pilihan Anda [1/2] = "<<endl;
        cin>>choice;
        switch (choice)
        {
        case 1:
            goto a;
            break;
        case 2:
            system ("csl");
            break;
        default:
            goto b;
            break;
        }
        break;

    }
}
C++

Semoga contoh program di atas dapat membantu Anda dalam memahami penggunaan looping dan menghasilkan deret bilangan dalam bahasa pemrograman C++.