Answer to Question #13415 in C# for Sifsilva

Question #13415
A phone call cost 10 cents per minute. Write a program that generates two random numbers for hours and minutes and calculate the cost of the call. Look at exercise 12.6page 224 that shows how to create a random number.(Note: there is no input from the user).
Button Make a call
When this button is clicked, two random numbers are generated. A call cannot be more than 5 hours long. The generated hours and minutes are displayed on labels. Calculate the cost of the call in minutes and display it on a label.
The use of correct types, formatting and constants will earn you marks.
Expert's answer
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Phone_call
public partial class Form1 : Form
private int hours;
private int minutes;
public Form1()

private void btnMakecall_Click(object sender, EventArgs e)
Random r =new Random();
hours = r.Next()%5;
minutes = r.Next()%60;
lblhours.Text = "Hours: "+hours.ToString();
lblminits.Text = "Minutes: " + minutes.ToString();
double cost=0;
cost = hours * 60 * 0.1 + minutes * 0.1;
lblcost.Text = "I will be cost $" + cost.ToString();

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!


No comments. Be the first!

Leave a comment

Ask Your question

New on Blog