Jump to content

self stud c# gettin a problem with this,

- - - - -

  • Please log in to reply
7 replies to this topic

#1
harddisk

harddisk

    Newbie

  • Members
  • PipPip
  • 12 posts
any body could help/show me a c# prog on how this one should be done :

amount ex: 50

amount changes per 3min of calls,

when, call reaches 4mins, amount becomes 100. ( start to 3min = 50)
when, call reaches 7min, amount becomes 150. ( 3.1 to 6 = 100)
and so on ...

minutes must be based on user input ..

someone help, sorry if my english is bad :)


#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Can you post the code that you currently have?
-CDG10620
Software Developer

#3
harddisk

harddisk

    Newbie

  • Members
  • PipPip
  • 12 posts
Console.WriteLine("Enter Call Duration: ");
double CallDuration = double.Parse(Console.ReadLine());
string rate = (string.Format("{0:N2}", ((50 / 3) * CallDuration)));
double payment = Convert.ToDouble(rate);
Console.Write(payment);

since I can only divide 50 by 3 to get the equivalent rate for each minute, and decimal places must not be rounded off

but 1 minute already is 50 as well as 2 and 3.
4 5 and 6 will be 100
7 8 9 will be 150
and so on,
can't find a way for this..


#4
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
This should be fairly simple for you to do as long as you're using whole numbers. If the user is truly entering a double then that complicates things a little bit and you may have to do some other calculating but if the rate is the same depending on the range then you should be able to write a function that calculates this. Let the call duration be divided by 3 and then multiply by fifty.
-CDG10620
Software Developer

#5
harddisk

harddisk

    Newbie

  • Members
  • PipPip
  • 12 posts
that double should be used that's why i considered it complicated, well if there could be a way, i might look up for it in the near future

#6
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
i still don't understand what you wanted , i am a bit dumb :crying: , analyze the psedocode below and tell i get your question right

var [COLOR=DarkOrange]_callDuration[/COLOR] = Get from user;
var [COLOR=Orange]_ratePerCall [/COLOR]= Fixed by Harddisk [that's you];
var [COLOR=Olive]_callsMade [/COLOR]= _callDuration / 3 ;
var [COLOR=Lime]nTotalCost [/COLOR]= [COLOR=MediumTurquoise]_callsMade * _ratePerCall [/COLOR];

Am i getting this right ?

#7
Matt Ellen

Matt Ellen

    Newbie

  • Members
  • PipPip
  • 14 posts
This does the trick for me:

 
int initialAmount = 50;
bool gotDuration = false;
double duration = 0.0;
while (!gotDuration)
{
    Console.Write("Please input the duration of the call: ");
    string strDuration = Console.ReadLine();
    gotDuration = Double.TryParse(strDuration, out duration);
    if (!gotDuration)
        Console.WriteLine("That is not a valid floating point number, please try again");
}

int charge = Convert.ToInt32(initialAmount * (Math.Ceiling(duration / 3.0)));
Console.WriteLine("Amount needed to be paid: {0}", charge);


#8
harddisk

harddisk

    Newbie

  • Members
  • PipPip
  • 12 posts

Matt Ellen said:

This does the trick for me:

 

int initialAmount = 50;

bool gotDuration = false;

double duration = 0.0;

while (!gotDuration)

{

    Console.Write("Please input the duration of the call: ");

    string strDuration = Console.ReadLine();

    gotDuration = Double.TryParse(strDuration, out duration);

    if (!gotDuration)

        Console.WriteLine("That is not a valid floating point number, please try again");

}


int charge = Convert.ToInt32(initialAmount * (Math.Ceiling(duration / 3.0)));

Console.WriteLine("Amount needed to be paid: {0}", charge);


i forgot about the ceiling,
Thanx a lot Matt , it worked! :thumbup:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users