In: Computer Science
Designed a Flowchart where you have to ask road type
and speed of the vehicle from user
and then decide whether a car is over-speeding, is under-speed or
it is moving with the allowed
speed. Develop program using C language The allowed speed limit is
given in the following table.
See the following conditions:
Road Type Speed Limit
Local Street 20-30 km/h
Main Street 31-40 km/h
Main Road 41-90 km/h
High way 91-110 km/h
Table 2: Normal (Allowed)
Flow chart:
Code:
#include <stdio.h>
int main(){
//variables to store road tye and speed
int road_type;
int speed;
//taking input from user
printf("1.Local Street\n2.Main Street\n3.Main
Road\n4.High way\nEnter Road type: ");
scanf("%d",&road_type);
printf("Enter speed: ");
scanf("%d",&speed);
//slection statements based on given conditions
//if any invalid input is entered then error is
printed
if(road_type==1){
if(speed<=30 &&
speed>=20){
printf("Moving
in Normal speed");
}
else if(speed<20){
printf("under
speed");
}
else if(speed>30){
printf("Over
speed");
}
else{
printf("error");
}
}
else if(road_type==2){
if(speed<=40 &&
speed>=31){
printf("Moving
in Normal speed");
}
else if(speed<31){
printf("under
speed");
}
else if(speed>40){
printf("Over
speed");
}
else{
printf("error");
}
}
else if(road_type==3){
if(speed<=90 &&
speed>=41){
printf("Moving
in Normal speed");
}
else if(speed<41){
printf("under
speed");
}
else if(speed>90){
printf("Over
speed");
}
else{
printf("error");
}
}
else if(road_type==4){
if(speed<=110 &&
speed>=91){
printf("Moving
in Normal speed");
}
else if(speed<91){
printf("under
speed");
}
else if(speed>110){
printf("Over
speed");
}
else{
printf("error");
}
}
else{
printf("Error");
}
}
Output:
Code Screenshot:
Code Snippet:
#include <stdio.h>
int main(){
//variables to store road tye and speed
int road_type;
int speed;
//taking input from user
printf("1.Local Street\n2.Main Street\n3.Main Road\n4.High way\nEnter Road type: ");
scanf("%d",&road_type);
printf("Enter speed: ");
scanf("%d",&speed);
//slection statements based on given conditions
//if any invalid input is entered then error is printed
if(road_type==1){
if(speed<=30 && speed>=20){
printf("Moving in Normal speed");
}
else if(speed<20){
printf("under speed");
}
else if(speed>30){
printf("Over speed");
}
else{
printf("error");
}
}
else if(road_type==2){
if(speed<=40 && speed>=31){
printf("Moving in Normal speed");
}
else if(speed<31){
printf("under speed");
}
else if(speed>40){
printf("Over speed");
}
else{
printf("error");
}
}
else if(road_type==3){
if(speed<=90 && speed>=41){
printf("Moving in Normal speed");
}
else if(speed<41){
printf("under speed");
}
else if(speed>90){
printf("Over speed");
}
else{
printf("error");
}
}
else if(road_type==4){
if(speed<=110 && speed>=91){
printf("Moving in Normal speed");
}
else if(speed<91){
printf("under speed");
}
else if(speed>110){
printf("Over speed");
}
else{
printf("error");
}
}
else{
printf("Error");
}
}