Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C++ illegal digit for base error...HELP! 1

Status
Not open for further replies.

temperoath

Programmer
Jul 10, 2003
4
0
0
US
Im a C++ student trying to write a simple telephone program. Im sure you guys can figure this out.
heres my code. When I compile I get "error C2041: illegal digit '8' for base '8'" on the first if statement.

#include <iostream>
using namespace std;

float net(float, int);

float gross;

int main()
{
float start = 0;
int length = 0;

cout<<&quot;Please enter a start time based on a 24 hour clock (i.e 1800 = 6:00pm):&quot;<<endl;
cin>>start;
cout<<&quot;Please enter the length of the call:&quot;<<endl;
cin>>length;

gross = length * 0.10;
cout<<&quot;The gross cost of this call before any discounts is: &quot;<<gross<<endl;

float net(float start, int length);

cout<<&quot;The net cost after all dicounts and including tax is: &quot;<<net<<endl;

return 0;
}


float net(float start, int length)
{
float discount1;
float discount2;
float net;

if (start >= 1800 && start <= 0800)
discount1 = gross * 0.50;

if (length >= 60)
discount2 = gross * .15;

net = gross - discount1 - discount2;
net = (net * 0.04) + net;

return net;
}
 
When you specify a numeric constant starting with 0 like 0800 the compiler considers this number to be octal.
In octal you can't have a digit 8 (Only 0-7)

Remove the leading 0.

/JOlesen
 
thanks,

If I do that wouldn't it still break because the user can enter 0800 (hours) for the time. Or will the program just eliminate the leading '0' that they enter.
 
program will convert the input into float, if can.
that means if user gives 00000800, 800, 800.0, 8E+2, 80E+1 will all be the same
if user gives 08 00 it will not work

note: user can input 800.1, may be it is not as you like, so try int

[ghost]


Greetings Andreas
 
Isn't your if statement always false?

if start is greater than 1800, than it is not less then 800.
if start is less then 800, then it is not greater than 1800.

(start >= 1800) and (start <= 800) can both never be true together, therefore your if statement is always false


if (start >= 1800 && start <= 0800)
discount1 = gross * 0.50;

 
also inside your program, inside the main(), your net function should be written as:

net(start,length);

not with the float net(int start....)

You don't need to put the type inside the main function. You put the types in function prototypes.
 
Thats true...i was thinking like a clock, too bad the compiler doesn't know!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top