@ d moment, am doing sum reading up on "SWITCHES" and am not sure if am doing the code properly.. so i could share the problem and share my code with u guys.. i wood love to
and if u can suggest any help i wwo greatly appreaciate it....
thanks

Write a program to solve the following problem. DO NOT USE AN IF-ELSE CASCADE.

Calculate the fine to be paid on a speeding ticket. If the automobile speed is less than 50 km/hr, there is no fine. If the speed is between 50 and 60 km/hr, the fine is $15. If the speed is between 60 and 70 km/hr, the fine is $30. If the speed is between 70 and 80 km/hr, the fine is $60. Finally, if the speed is over 80 km/hr, the fine is $150.
Print out the speed and the fine, or the words “no fine” if there is no fine


my codes....

#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>

int main(int nNumbersofArgs,char*pszArgs[])
{
int speed;
int Letter;
int a, b, c, d, e;

cout<<"Enter the speed of the automobile"<<endl;
cin>>speed;

cout<<"The following are speeds that are categorized"<<endl<<endl;
cout<<"a = speed is <50 Km/hr"<<endl;
cout<<"b = speed is >50 and <=60 Km/hr"<<endl;
cout<<"c = speed is >60 and <=70 Km/hr"<<endl;
cout<<"d = speed is >70 and <=80 Km/hr"<<endl;
cout<<"e = speed is >80 Km/hr"<<endl<<endl;

a = speed <50;
b = speed >50 && speed <=60;
c = speed >60 && speed <=70;
d = speed >70 && speed <80;
e = speed >80;

cout<<"Enter the Letter of the category that the speed of the automobile is in; ";
cin>>Letter;

switch (speed)
{
case 'A': case 'a':
cout<<"Speed is " ;
cout<<speed;
cout<< " Km/hr and there is No Fine"<<endl;
break;
case 'B': case 'b':
cout<<"Speed is " ;
cout<<speed;
cout<< " Km/hr and the Fine is $15.00 "<<endl;
break;
case 'C': case 'c':
cout<<"Speed is " ;
cout<<speed;
cout<< " Km/hr and the Fine is $30.00"<<endl;
break;
case 'D': case 'd':
cout<<"Speed is " ;
cout<<speed;
cout<< " Kn/hr and the Fine is $60.00"<<endl;
break;
case 'E': case 'e':
cout<<"Speed is " ;
cout<<speed;
cout<< " Km/hr and the Fine is $150.00"<<endl;
break;
defalt:
cout<<"Invalid Speed";
cout<<endl;
}

system("PAUSE");
return 0;
}

any suggestions as to wats wrong?? cause am not sure if am doing the SWITCH correct!!!!! thanks in advance

Member Avatar for jencas
switch (speed)
{
case 'A': case 'a':

You are comparing the speed to a category. That doesn't work!

delete lines 21-25 because that is just meaningless crap.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.