Click here to Skip to main content
15,913,361 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
create a C# application that calculate and displays membership fees for N customers who registered for membership
Length of MembershipRate(including tax)
1-8weeks $40.0per
week8-16weeks $35.5per week
More than 16weeks $25.0per week

the application should ask the user to enter the customer name, the number of months for membership, and yes or no to indicate whether the customer receives a special offer or not. The special offer will give customers a 20% discount of the membership no matter how many weeks they register. Assume that the number of week to be entered is an integer type with the range between 1 and 30. An error message should be issued if a user enters a value beyond this range and the re-entering is required.The program makes a calculation of membership and displays the result as shown in the below figure. The program should be kept running with entering next set of input data

What I have tried:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GymMembership
{
public class exercise18
{
static void Main(string[] args)
{
int weeks;
bool specialOffer;
double discount = 20 , totalAmount = 0;
string name;

Console.Write("\n\n");
Console.Write("Calculate membership fees:\n");
Console.Write("----------------------------");
Console.Write("\n\n");

Console.Write("Input number of weeks :");
weeks = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the name of the customer :");
name = Console.ReadLine();
Console.Write("Input the special offer by the customer : ");
specialOffer = Convert.ToBoolean(Console.ReadLine());
if (weeks <= 8)
totalAmount = (((40.0 * weeks) * discount / 100) - (40.0 * weeks));
else if (weeks > 8)
totalAmount = (((35.5 * weeks) * discount / 100) - (35.5 * weeks));
else if (weeks > 16)
totalAmount = (((25.0 * weeks) * discount / 100) - (25.0 * weeks));
else (weeks > 30){
Console.WriteLine("error");
}
Console.Write("\nElectricity Bill\n");
Console.Write("Customer IDNO :{0}\n", weeks);
Console.Write("Customer Name :{0}\n", name);
Console.Write("special offer :{0}\n", specialOffer);
Console.Write("discount Amount :{0}\n", discount);
Console.Write("Net Amount Paid By the Customer :{0}\n", totalAmount);
}
}
}
Posted
Updated 26-Dec-17 1:52am
Comments
Patrice T 25-Dec-17 1:10am    
And you probably have a question or a problem in your code ?
Member 13592581 25-Dec-17 23:43pm    
Can you write code for this problem with correction

C#
totalAmount = (((40.0 * weeks) * discount / 100) - (40.0 * weeks));
totalAmount = (((35.5 * weeks) * discount / 100) - (35.5 * weeks));
totalAmount = (((25.0 * weeks) * discount / 100) - (25.0 * weeks));

I fear your formula for totalAmount is wrong.
 
Share this answer
 
Your total amount calculation is wrong :

totalAmount = (((40.0 * weeks) * discount / 100) - (40.0 * weeks));


instead it should be :

totalAmount =  (40.0 * weeks)) - (((40.0 * weeks) * discount / 100) ;


so for 2 weeks : cost will be 40*2 = 80$

and 20% discount : 64$

totalAmount =  (40.0 * weeks)) - (((40.0 * weeks) * discount / 100) ;


= 80 - (80 * 0.2)
= 80 - 16
= 64$

hope this helps
 
Share this answer
 
Comments
Shashank Laxman 26-Dec-17 8:14am    
why answer is downvoted,i only corrected logic
Patrice T 26-Dec-17 8:29am    
Probably because I already spotted the problem in my solution.
And since my solution was accepted, it means that the OP found the correction by himself once he knew where was the problem.

Advice: try to answer unanswered questions or try to add something useful in your solutions.

the fact that your corrected formulas have errors may not help either.
Shashank Laxman 26-Dec-17 8:32am    
Ok thanks for clarification,ur posts are valuable
Shashank Laxman 26-Dec-17 8:34am    
Can you write code for this problem with correction
This was posted by Member 13592581

I only corrected by giving an example
Patrice T 26-Dec-17 8:42am    
Basically, you got the correction, just parenthesis are wrong.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900