pada kali ini saya akan share coding mencari nilai rata-rata umur
silahkan lihat gambar berikut ini
copy paste aja koding berikut ini :)
silahkan lihat gambar berikut ini
copy paste aja koding berikut ini :)
#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string>
using namespace std;
struct node
{
int nim;
float umur;
char alamat[10];
string nama;
struct node *next;
};
main()
{
struct node *n, *t, *h, *t1;
char jawab = 'y';
float total = 0;
int jumlahinput =0;
float rata;
n = t = h = NULL;
while (jawab != 'n')
{
n=new node;
cout << "Input NIM :";
cin >> n -> nim;
cout << "Input Nama:";
cin >> n -> nama;
cout<< " Input alamat : ";
cin>> n -> alamat;
cout << "input umur : ";
cin >> n -> umur;
total= n ->umur;
jumlahinput++;
if (h == NULL)
{
t = n;
h = n;
}
else
{
t -> next = n;
t = n;
}
cout << "Input lagi? (y/n) : ";
cin >> jawab;
cout << "\n";
}
cout<<"-------------------------------------------------------------- \n";
cout<<"\n"<<"NIM"<<"\t"<<"Nama"<<"\t"<<"Alamat"<<"\t"<<"umur"<<"\n";
cout<<"---------------------------------------------------------------\n";
t1=h;
while (t1 -> next != NULL)
{ cout << t1 -> nim<<"\t"<<t1 -> nama <<"\t"<< t1 ->alamat<<"\t"<< t1 -> umur<< "\n\n";
total =total + t1 -> umur;
rata = total/jumlahinput;
t1 = t1 -> next;
}
cout << t1 -> nim <<"\t"<< t1 -> nama <<"\t"<< t1 ->alamat<<"\t"<< t1 -> umur<< "\n\n";
cout<<"---------------------------------------------------\n";
cout << "\n" <<"rata rata umur : ";
cout << total;
getch();
}
sekian dan terima kasih :)
#include <conio.h>
#include <stdio.h>
#include <string>
using namespace std;
struct node
{
int nim;
float umur;
char alamat[10];
string nama;
struct node *next;
};
main()
{
struct node *n, *t, *h, *t1;
char jawab = 'y';
float total = 0;
int jumlahinput =0;
float rata;
n = t = h = NULL;
while (jawab != 'n')
{
n=new node;
cout << "Input NIM :";
cin >> n -> nim;
cout << "Input Nama:";
cin >> n -> nama;
cout<< " Input alamat : ";
cin>> n -> alamat;
cout << "input umur : ";
cin >> n -> umur;
total= n ->umur;
jumlahinput++;
if (h == NULL)
{
t = n;
h = n;
}
else
{
t -> next = n;
t = n;
}
cout << "Input lagi? (y/n) : ";
cin >> jawab;
cout << "\n";
}
cout<<"-------------------------------------------------------------- \n";
cout<<"\n"<<"NIM"<<"\t"<<"Nama"<<"\t"<<"Alamat"<<"\t"<<"umur"<<"\n";
cout<<"---------------------------------------------------------------\n";
t1=h;
while (t1 -> next != NULL)
{ cout << t1 -> nim<<"\t"<<t1 -> nama <<"\t"<< t1 ->alamat<<"\t"<< t1 -> umur<< "\n\n";
total =total + t1 -> umur;
rata = total/jumlahinput;
t1 = t1 -> next;
}
cout << t1 -> nim <<"\t"<< t1 -> nama <<"\t"<< t1 ->alamat<<"\t"<< t1 -> umur<< "\n\n";
cout<<"---------------------------------------------------\n";
cout << "\n" <<"rata rata umur : ";
cout << total;
getch();
}
sekian dan terima kasih :)
Jangan Lupa commen nya dan kunjungi terus blog saya http://berbagitips46.blogspot.com atau http://sahatpg.wordpress.com/
supaya saya lebih giat lagi untuk mencari aplikasi-aplikasi yang
terbaru atau anda bisa request software yang anda ingin kan siapa tau
saya bisa bantu cari
sekian terimakasih semoga bermanfaat ^_^
sekian terimakasih semoga bermanfaat ^_^
0 comments:
Post a Comment