BTC USD 81,813.4 Gold USD 4,378.12
Time now: Jun 1, 12:00 AM

convert C++ to C#

salamvtr

Freshie
Messages
3
Joined
Jan 3, 2009
Messages
3
Reaction score
0
Points
3
salam,

ade tak sape2 boleh tolong tukarkan skrip C++ dibawah ini kepada skrip C

#include <iostream>
#include <cmath>
#include <conio.h>
using namespace std;

int main()
{
int account;
char code;
double gallons, bill;

cout << "Enter your account number:" << endl;
cin >> account;

cout << "Now enter your code(h,c, or i):" << endl;
cin >> code;

cout << "Now enter the amount of gallons of water used:" << endl;
cin >> gallons;

if (code == 'h')
{
bill = 5 + (gallons * 0.0005);
**
if (code == 'c' && gallons > 4000000)
{
bill = 1000 + ((gallons - 4000000) * 0.00025);
**
else if (code == 'c' && gallons <= 4000000)
{
bill = 1000;
**
if (code == 'i' && gallons <= 4000000)
{
bill = 1000;
**
else if (code == 'i' && gallons < 4000000 && gallons > 10000000)
{
bill = 2000;
**
else if (code == 'i' && gallons >= 10000000)
{
bill = 3000;
**

cout << "The bill for account number: " << account << ", will be: $" << bill << endl;
getch();
return 0;

**
 
Aku tak pandai sangat, tah betul ke tidak wallahuaklam..

Code:
using System;

namespace ConsoleApplicationTest1
{
    class Program
    {
        static void Main(string[] args)
        {
            int account;
            string code;
            double gallons, bill=0;

            Console.WriteLine("Enter your account number:");
            account = int.Parse(Console.ReadLine());

            Console.WriteLine("Now enter your code(h,c, or i):");
            code = Console.ReadLine();

            Console.WriteLine("Now enter the amount of gallons of water used:");
            gallons = double.Parse(Console.ReadLine());

            if (code == "h") 
            {
                bill = 5 + (gallons * 0.0005);
            **
            
            if (code == "c" && gallons > 4000000) 
            {
                bill = 1000 + ((gallons - 4000000) * 0.00025);
            **            
            else if (code == "c" && gallons <= 4000000)
            {
                bill = 1000;
            **
            
            if (code == "i" && gallons <= 4000000)
            {
                bill = 1000;
            **
            else if (code == "i" && gallons < 4000000 && gallons > 10000000)
            {
                bill = 2000;
            **
            else if (code == "i" && gallons >= 10000000)
            {
                bill = 3000;
            **
            Console.WriteLine("The bill for account number: " + account.ToString() + ", will be: $" + bill.ToString());
        **
    **
**
 
Back
Top
Log in Register