Array adalah suatu struktur yang terdiri sejumlah elemen yang
memiliki tipe data yang sama. Elemen-elemen array tersusun secara
sekuensial dalam memmory komputer. Array dapat berupa satu dimensi, dua
dimensi, tiga dimensi ataupun banyak dimensi ( multi dimensi ). Bentuk
umum array sendiri antara lain :
<tipe data> || Nama Array = new < tipe data>[m];
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] barang = new string[20];
int[] hrg = new int[20];
int[] jml = new int[20];
int[] tot = new int[20];
int i, n, total = 0, bayar;
Console.Write("Masukan Jumlah barang yang di beli = ");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
Console.WriteLine("Masukan data barang ke-" + i);
Console.WriteLine("\t Masukan nama barang = ");
barang[i] = Console.ReadLine();
Console.Write("\tMasukan harga barang = ");
hrg[i] = int.Parse(Console.ReadLine());
Console.Write("\tMasukan jumlah barang = ");
jml[i] = int.Parse(Console.ReadLine());
tot[i] = hrg[i] * jml[i];
total = total + tot[i];
}
Console.Clear();
Console.WriteLine("=======================================");
Console.WriteLine(" Sistem Penjualan Swalayan Laris ");
Console.WriteLine("========================================");
Console.WriteLine(" No | Nama Barang \tHarga \tJumlah \tTotal ");
Console.WriteLine("---------------------------------------");
for (i=1; i<= n ; i++)
{
Console.WriteLine(i+" "+barang[i] +"\t"+hrg[i]+ "\t"+jml[i]+"\t"+tot[i]);
}
Console.WriteLine("=======================================");
Console.WriteLine("Jumlah Total Bayar = " +total);
byr:
Console.Write("Masukan Uang Bayar = ");
bayar = int.Parse(Console.ReadLine());
Console.WriteLine("Uang kembalian anda = " + (bayar - total));
Console.WriteLine("==============================================");
Console.WriteLine(" TERIMA KASIH ");
Console.Read();
}
}
}
<tipe data> || Nama Array = new < tipe data>[m];
Membuat Sistem Penjualan Swalayan ( C# / C Sharp ) |
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] barang = new string[20];
int[] hrg = new int[20];
int[] jml = new int[20];
int[] tot = new int[20];
int i, n, total = 0, bayar;
Console.Write("Masukan Jumlah barang yang di beli = ");
n = int.Parse(Console.ReadLine());
for (i = 1; i <= n; i++)
{
Console.WriteLine("Masukan data barang ke-" + i);
Console.WriteLine("\t Masukan nama barang = ");
barang[i] = Console.ReadLine();
Console.Write("\tMasukan harga barang = ");
hrg[i] = int.Parse(Console.ReadLine());
Console.Write("\tMasukan jumlah barang = ");
jml[i] = int.Parse(Console.ReadLine());
tot[i] = hrg[i] * jml[i];
total = total + tot[i];
}
Console.Clear();
Console.WriteLine("=======================================");
Console.WriteLine(" Sistem Penjualan Swalayan Laris ");
Console.WriteLine("========================================");
Console.WriteLine(" No | Nama Barang \tHarga \tJumlah \tTotal ");
Console.WriteLine("---------------------------------------");
for (i=1; i<= n ; i++)
{
Console.WriteLine(i+" "+barang[i] +"\t"+hrg[i]+ "\t"+jml[i]+"\t"+tot[i]);
}
Console.WriteLine("=======================================");
Console.WriteLine("Jumlah Total Bayar = " +total);
byr:
Console.Write("Masukan Uang Bayar = ");
bayar = int.Parse(Console.ReadLine());
Console.WriteLine("Uang kembalian anda = " + (bayar - total));
Console.WriteLine("==============================================");
Console.WriteLine(" TERIMA KASIH ");
Console.Read();
}
}
}
0 komentar
Posting Komentar