Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

C# Sharp Exercises: Calculate profit and loss


C# Sharp Conditional Statement: Exercise-17 with Solution

Write a C# Sharp program to calculate profit and loss on a transaction.

Sample Solution:-

C# Sharp Code:

using System;  
public class Exercise17  
{  
    public static void Main()  
{  
    int cprice,sprice, plamt; 

           Console.Write("\n\n");
           Console.Write("Calculate profit and loss:\n");
           Console.Write("----------------------------");
           Console.Write("\n\n");
      

     Console.Write("Input Cost Price: ");  
     cprice= Convert.ToInt32(Console.ReadLine()); 
     Console.Write("Input Selling Price: ");  
     sprice= Convert.ToInt32(Console.ReadLine());  
      
    if(sprice>cprice) 
    {  
        plamt = sprice-cprice;  
        Console.Write("\nYou can booked your profit amount : {0}\n", plamt);  
    }  
    else if(cprice>sprice)  
    {  
        plamt = cprice-sprice;  
        Console.Write("\nYou got a loss of amount : {0}\n", plamt);  
    }  
    else   
    {  
        Console.Write("\nYou are running in no profit no loss condition.\n");  
    }  
}
}  
  

Sample Output:

Calculate profit and loss:                                                                                    
----------------------------                                              
Input Cost Price: 1000                                                                                        
Input Selling Price: 1200                                                                                     
                                                                                                              
You can booked your profit amount : 200 

Pictorial Presentation:

Conditional Statement: Calculate profit and loss.

Pictorial Presentation:

Conditional Statement: Calculate profit and loss.

Flowchart:

Flowchart: Calculate profit and loss.

C# Sharp Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a C# Sharp program to check whether an alphabet is a vowel or consonant.
Next: Write a program in C# Sharp to calculate and print the Electricity bill of a given customer.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.