What's new

Need help po any languange sa tatlo C, C++, or Java

Cutthroat

Forum Veteran
Joined
Sep 20, 2016
Posts
1,653
Solutions
57
Reaction
2,394
Points
752
Age
22
Consider the situation of issuing parking tickets on campus and determining the fines associated with the ticket. All students are charged an initial 75.00 when ticketed. Additional charges are based on how much over the speed limit the ticket reads. There is a 35 miles per hour (MPH) speed limit on most streets on campus. Two roads are posted with a speed limit at 15 MPH. Fines are expensive on campus. After the initial 75.00 fee, an extra 87.50 is charged for every 5 MPH students are clocked over the speed limit.
The traffic office feels seniors have been around for a while and should know better than to speed on campus. They add even more fees to their fine. At the same time, they try to cut freshmen a little slack. Seniors are charged an extra 50.00 when they get caught speeding, unless they are traveling more than 20 MPH over the speed limit. Then they are charged an extra 200.00.
If freshmen are exceeding the speed limit by less than 20 MPH, they get a 50.00 deduction off their fines. But, freshmen, sophomores, and juniors traveling 20 MPH or more are fined an additional 100.00.

Salamat po sa tutulong <3
 
meron po kaso di na maintindihan hahahaha nagugulohan ako sa switch case baka naman po maka tulong ka po
 
[XX='Hoshiumi, c: 477407, m: 631418'][/XX] ano na po ang nagawa mo? suggest ko lang gawa ka muna ng table sa excel para ma-visual mo yung mga conditions nakakalito kasi in words
 
supposed to be po ganito kalabasan ng output

using System;

class Program
{
static void Main()
{
int rank, speedOver;
double cost;
Console.Write("What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) ");
rank = Convert.ToInt32(Console.ReadLine());
Console.Write("How many miles over the speed limit were you travelling? ");
speedOver = Convert.ToInt32(Console.ReadLine());
cost = GetTicketCost(rank, speedOver);
Console.WriteLine("The cost of the ticket is $" + cost);
}

public static double GetTicketCost(int rank, int speedOver)
{
double charges = 0;
if(speedOver > 0)
{
charges = 75; //initial charges
int numFives = speedOver / 5;
charges += numFives * 87.50;
if(rank == 4) //senior
{
if(speedOver > 20)
charges += 200; //200 if more than 20mph over speed limit
else
charges += 50;
}
else //for freshmen, sophomores, juniors
{
if(speedOver > 20)
charges += 100;
else if(rank == 1) //freshmen less than 20mph above speed limit
charges -= 50;
}

}
return charges;
}
}

output

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 1
How many miles over the speed limit were you travelling? 1
The cost of the ticket is $25

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 1
How many miles over the speed limit were you travelling? 19
The cost of the ticket is $287.5

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 1
How many miles over the speed limit were you travelling? 21
The cost of the ticket is $525

What's your rank? (1=Freshman , 2=Sophomore, 3=Junior, 4=Senior) 2
How many miles over the speed limit were you travelling? 1
The cost of the ticket is $75
 
[XX='Hoshiumi, c: 477444, m: 631418'][/XX] di ko din sure e hehe pero almost same lang naman code ng c# sa c++
 
Back
Top