| // array char, double, function, calculation, max<br>3 function : รับเข้าอาเรย์, คำนวณและแสดง, หาผลรวม
/* http://www.thaiall.com/tc */
#include <conio.h>
#include <stdio.h>
#include <iostream.h>
void x1();
void x2();
void x3();
char *n[4]={"    ","    ","    ","    "};
double c[4] ={0,0,0,0};
double s[4] ={0,0,0,0};
double t[4] ={0,0,0,0};
int i,max;
void main() {
  clrscr();
  cout << "How much : ";
  cin >> max;
  x1();
  x2();
  x3();
  getch();
}
void x1() {
  for (i=0;i<max;i++) {
    cout << "Name : ";
    cin >> n[i];
    cout << "Cream : ";
    cin >> c[i];
    cout << "Soap : ";
    cin >> s[i];
  }
}
void x2() {
  for (i=0;i<max;i++) {
    cout << n[i] << " : ";
    cout << c[i] << " : ";
    cout << s[i] << " : ";
    t[i] = (c[i] * 0.05) + (s[i] * 0.1);
    cout << t[i] << "\n";
  }
}
void x3() {
 double x=0;
 for (i=0;i<max;i++) {
    x = x + t[i];
  }
 cout << "Total : "<< x;
} |  |