[Source]
void SchoolZone()
{
std::cout << "\n\nWas the vehical speeding in a schoolzone?" << std::endl;
std::cout << "[1/0]: "; // 1 = yes, 0 = no
std::cin >> yesNoSchool;
if (yesNoSchool == 1) // if car was speeding in school zone, option 1
{
std::cout << "\n\nThe vehical was speeding in a school zone.";
TicketYes(); //calls TicketYes function (diffrent fines)
}
else //if not speeding in school zone, option 2
{
std::cout << "\n\nThe vehical was not speeding in a school zone.";
TicketNo(); //calls ticketNo function (diffrent fines)
}
}
[/Source]
[Source]
#include <iostream>
#include <conio.h>
//prototypes
void VehicalSpeed();
void SpeedLimit();
void SchoolZone();
void TicketYes(); //yes schoolzone ticket function
void TicketNo(); //no schoolzone ticket function
//Global vars
int speed; //vehical speed
int speedLimit; //road speed limit
int yesNoSchool; // yes/no school zone
int rSpeedCharge = 30; // regular speeding charge
int x; // miles over/under the speed limit
//main function
int main()
{
SpeedLimit(); // calls SpeedLimit function
VehicalSpeed(); // calls VehicalSpeed funtion
getch(); //stops console from flashing by.
return 0; // I still gotta look this up sometime...
}
//Function info
void SpeedLimit()
{
std::cout << "**********SPEEDING TICKET**********" << std::endl << std::endl;
std::cout << "\nWhat is the speed limit of the area: "; //prompts for speed limit
std::cin >> speedLimit;
}
void VehicalSpeed()
{
std::cout << "How fast was the vehical going: "; //prompts for vehical speed
std::cin >> speed;
if (speed > speedLimit) //if the speed is greater than limit, option 1
{
x = speed - speedLimit; //assigns x to vehical speed - speedlimit
std::cout << "\n\nOver the speed limit by " << x << " miles" << std::endl;
SchoolZone(); //calls the SchoolZone function
}
else //if speed was less than limit, option 2 starts
{
x = speedLimit - speed; // assigns x to speed limit - vehical speed
std::cout << "\n\nUnder the speed limit by " << x << " miles" << std::endl;
}
}
void SchoolZone()
{
std::cout << "\n\nWas the vehical speeding in a schoolzone?" << std::endl;
std::cout << "[1/0]: ";
std::cin >> yesNoSchool;
if (yesNoSchool == 1) // if car was speeding in school zone, option 1
{
std::cout << "\n\nThe vehical was speeding in a school zone.";
TicketYes(); //calls TicketYes function (diffrent fines)
}
else //if not speeding in school zone, option 2
{
std::cout << "\n\nThe vehical was not speeding in a school zone.";
TicketNo(); //calls ticketNo function (diffrent fines)
}
}
void TicketYes()
{
std::cout << "\n\nRegular speed ticket fine: " << rSpeedCharge << std::endl;
std::cout << "Extra charge per MPH: " << 6.00 << std::endl;
std::cout << "\nFinal Ticket Charge: " << (rSpeedCharge + (x * 6.00))
<< std::endl; // ^^figures out and adds up the numbers
}
void TicketNo()
{
std::cout << "\n\nRegular speed ticket fine: " << rSpeedCharge << std::endl;
std::cout << "Extra charge per MPH: " << 3.00 << std::endl;
std::cout << "\nFinal Ticket Charge: " << (rSpeedCharge + (x * 3.00))
<< std::endl; // ^^figures out and adds up the numbers
}
[/Source]