Question

In C# You will be prompting the user for a text string a list of bills...

In C# You will be prompting the user for a text string a list of bills they have every month.

a. This should be a comma separated list , bill1, bill2, bill3

b. Validate that this text string is not left blank.

3. Create a custom function called CreateBillArray

a. This function should accept the string variable that holds the bills.

b. Inside of the function, split the text string of the bills into a string array with each individual bill in its own array element.

c. Make sure to remove any spaces before or after the bill itself.

d. Return this string array back to the Main.

4. Create a custom function called BillCosts.

a. This function should accept the string array of bills.

b. Inside of this function create an array to hold the cost of each bill.

c. Loop through the bill string array and prompt the user for the cost of each individual bill. i. Make sure to validate this user prompt.

d. After you get each cost, Return this array to the Main.

5. Create a 3rd custom function called TotalOfBills.

a. This function should accept the decimal array of the bill costs as a parameter.

b. Inside of the function, create a variable to hold the total sum of all of the bills.

c. Create a loop and cycle through the array of costs and add them all up.

d. Return this monthly total for the bills back to the Main.

6. Now you will ask the user for one more piece of information, making sure you validate and convert it to the correct data type.

a. Prompt the user for the number of months that they would like to see.

7. Using the amount of months request and the average cost per month, calculate the amount they will owe in bills.

8. The final output to the user should be done in the Main and follow this format.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Create a new C# console application with the name Bills, add the below code in Program.cs

Program.cs

using System;

namespace Bills
{
class Program
{
static void Main(string[] args)
{
String strBills;
//prompt the user for a text string a list of bills they have every month
Console.Write("Enter the list of bills (comma separated list): ");
strBills = Console.ReadLine();
//Validate that this text string is not left blank
while (strBills.Trim() == "")
{
Console.WriteLine("List cannot be empty.");
//prompting the user for a text string a list of bills they have every month
Console.Write("Enter the list of bills (comma separated list): ");
strBills = Console.ReadLine();
}
//get the bills
String[] bills = CreateBillArray(strBills);
//get the cost of each bill
decimal[] costOfEachBill = BillCosts(bills);
//get the total of all the bills
decimal totalOfAllBills = TotalOfBills(costOfEachBill);

//Prompt the user for the number of months that they would like to see
int numOfMonths;
Console.Write("Enter the number of months you would like to see: ");
bool res = Int32.TryParse(Console.ReadLine(), out numOfMonths);
while (!res)
{
Console.Write("Enter the number of months you would like to see: ");
res = Int32.TryParse(Console.ReadLine(), out numOfMonths);
}

//calculate the amount owed
decimal amtOwed = numOfMonths * totalOfAllBills;

//display the results
Console.WriteLine("\nYour bills for 1 month come out to $" + totalOfAllBills.ToString("0.00"));
Console.WriteLine("For " + numOfMonths + " months, you will owe $" + amtOwed.ToString("0.00"));
Console.Write("\nPress any key to continue...");
Console.ReadKey();
}

//Function that takes the list of bills as String and returns a string array splitting the list
public static string[] CreateBillArray(String strBills)
{
//split the list based on comma
String[] bills = strBills.Split(',');
strBills = strBills.Trim();
//store the list in array
for (int i = 0; i < bills.Length; i++)
{
//remove the trailing spaces in the bills and store them in array
bills[i] = bills[i].Trim();
}
return bills;
}

//Function that prompts and reads the cost of each bill
public static decimal[] BillCosts(String[] bills)
{
//create an array to hold the cost of each bill
decimal[] costOfEachBill = new decimal[bills.Length];
//iterate through all the bill items
for (int i = 0; i < bills.Length; i++)
{
//prompt and read the cost of bill
Console.Write("Enter the cost of bill for " + bills[i] + ": ");
costOfEachBill[i] = Convert.ToDecimal(Console.ReadLine());
//if cost is not valid prompt for valid cost
while (costOfEachBill[i] <= 0)
{
Console.Write("Enter a valid cost of the bill.");
//prompt and read the cost of bill
Console.Write("Enter the cost of bill for " + bills[i] + ": ");
costOfEachBill[i] = Convert.ToDecimal(Console.ReadLine());
}
}
return costOfEachBill;
}

//Function that computes and returns the totalOfAllBills of all the bills
public static decimal TotalOfBills(decimal[] costOfEachBill)
{
decimal totalOfAllBills = 0;
//iterate through all the bills and compute the total cost of bills
for (int i = 0; i < costOfEachBill.Length; i++)
//add each bill to the total
totalOfAllBills = totalOfAllBills + costOfEachBill[i];
return totalOfAllBills;
}
}
}

Output:

file:///E:/DotNet/Bills/Bills/bin/Debug/Bills.EXE Enter the list of bills (comma separated list): bill1, bill2, bill3, bill4

Add a comment
Know the answer?
Add Answer to:
In C# You will be prompting the user for a text string a list of bills...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • MUST BE WRITTEN IN C++ All user input values will be entered by the user from...

    MUST BE WRITTEN IN C++ All user input values will be entered by the user from prompts in the main program. YOU MAY NOT USE GLOBAL VARIABLES in place of sending and returning data to and from the functions. Create a main program to call these 3 functions (5) first function will be a void function it will called from main and will display your name and the assignment, declare constants and use them inside the function; no variables will...

  • Show data: Show Name (string- up to 25 characters, may not be blank) Show Date (mm/dd/yyyy,...

    Show data: Show Name (string- up to 25 characters, may not be blank) Show Date (mm/dd/yyyy, in that format) Show Fee to Participate (float, >-0) Show Sales (float, >-0) Miscellaneous Costs (float, >-0) Rate the Show(rating must be one of those 5 choices) Above maino, create a structure that will hold the information listed above. Then inside of main) create an array of 10 structures. Each structure in the array will represent a different show. Rules of the program: Option...

  • IN C language Write a C program that prompts the user to enter a line of...

    IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...

  • C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the...

    C++ Program Int Main First Please Write one program that does the following: 1.       1.   Ask the user for ten (10) grades, and store the data in an array.  Compute the average of all the grades.  Print the original ten grades and the average. a.       Declare an integer array with the name of “grades” of size 10 in the main function. b.      Create a function called “getGrades” that prompts the User for the grades and puts them in an integer array.                                                                i.      The function will receive...

  • Instructions Write a program called stocks.cpp. The program should prompt the user for the number of...

    Instructions Write a program called stocks.cpp. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none of these values can be less than zero) and should then pass them to a function called calculateProfit. The function should use the following formula to determine the...

  • (1) Prompt the user to enter a string of their choosing. Store the text in a...

    (1) Prompt the user to enter a string of their choosing. Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue! You entered: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews...

  • C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need...

    C++ (1) Prompt the user to enter a string of their choosing (Hint: you will need to call the getline() function to read a string consisting of white spaces.) Store the text in a string. Output the string. (1 pt) Ex: Enter a sample text: We'll continue our quest in space. There will be more shuttle flights and more shuttle crews and, yes, more volunteers, more civilians, more teachers in space. Nothing ends here; our hopes and our journeys continue!...

  • using C language Create an array of doubles with 5 elements. In the array prompt the...

    using C language Create an array of doubles with 5 elements. In the array prompt the user to enter 5 temperature values (in degree Fahrenheit). Do this within main. Create a user defined function called convert2Cels. This function will not return any values to main with a return statement. It should have parameters that include the temperature array and the number of elements. The function should convert the values for Fahrenheit to Celsius and save them back into the same...

  • Objectives: Use strings and string library functions. Write a program that asks the user to enter...

    Objectives: Use strings and string library functions. Write a program that asks the user to enter a string and output the string in all uppercase letters. The program should then display the number of white space characters in the string. You program should run continuously until the user enters an empty string. The program must use the following two functions: A function called count_spaces that counts the number of white spaces inside a string. int count_space(char str[]); which tell you...

  • c++ if you answer the question please write it line by line and not in paragrapth...

    c++ if you answer the question please write it line by line and not in paragrapth form. Write a C++ program that uses a structure named Movie to store the following. a. Title b. Director c. Year Released d. Running time (in minutes) e. Cost of production f. Revenue (first year). Create an array of type Movie of size 3. In your main program should then have in a loop (3 times) called a function called getData() and the purpose...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT