Tuesday, July 31, 2012
របៀបសរសេរកូដ គណនាថ្លៃភ្លើង ដោយប្រើ C-Program
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
Again:
clrscr();
float old_number,new_number,use_number,total,total1;
char ch;
printf("\n\n");
textcolor(YELLOW);
cprintf(" ****************************************");
printf("\n");
cprintf(" ** WELCOME TO ELECTRICITY OF CAMBODIA **");
printf("\n");
cprintf(" ****************************************");
old_A:
printf("\n\n\n");
textcolor(WHITE);
cprintf(" Input Old_number: ");
textcolor(YELLOW);
cscanf("%f",&old_number);
if(old_number<0)
goto old_A;
old_B:
printf("\n\n");
textcolor(WHITE);
cprintf(" Input New_number: ");
textcolor(YELLOW);
cscanf("%f",&new_number);
if(new_number<old_number)
goto old_B;
printf("\n\n\n");
use_number = new_number - old_number;
textcolor(YELLOW);
cprintf(" You used: %.f KW",use_number);
if(use_number<=50)
{
total = use_number * 350;
total1= total / 4000;
}
else if(use_number<=100)
{
total = (50*350)+((use_number-50)*550);
total1= total / 4000;
}
else if(use_number<=200)
{
total = (50*350)+(51*550)+((use_number-100)*750);
total1= total / 4000;
}
else
{
total = (50*350)+(51*550)+(101*750)+((use_number-200)*850);
total1= total / 4000;
}
printf("\n\n");
textcolor(YELLOW);
cprintf(" Total Balance (Riel): %.f R",total);
printf("\n\n");
textcolor(YELLOW);
cprintf(" Total Balance (Dollar): %0.2f $",total1);
printf("\n\n\n");
textcolor(WHITE);
cprintf(" *** Run Program Again *** (y/n)? Answer: ");
fflush(stdin);
ch=getchar();
if(ch=='Y'||ch=='y')
goto Again;
else
exit(1);
printf("\n\n");
getch();
}
Output:
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment