hey all, am a student of the University of Trinidad and Tobago. Am doing Computer Engineering - programming dip-bsc then masters- major in cryptgy...
any hows. am fascinated bout programming. if theres a code i have to write, i wouldnt 4 a sec leavt it until i get it to run...
i really love programming also i like to do web page design...

well i really came on here to be a part of the programmers forum- taughts and to share ideas....
i am seeking a greater help and understanding in programming -
C++ and java and netbeans...
so i hope to start interacting with u guys soon,,,,,,,

2
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by jessejamesjjr

at the 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

Edited by mike_2000_17: Fixed formatting

I will study first the codes you have given, I can't post a relevant reply for now. I will just post it later.

ok thanks alot look 4ward to ur help cause am still reading but am not sure if am doing the switch correct!!

hey guys thanks alot 4 ur time i figured it out....
i was jus missing out main (void)
so heres d code now and it works corectly...

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

int main(void)
{
int speed;
char 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 (Letter)
{

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<< " Km/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;
}

system("PAUSE");
return 0;
}