Hello everybody, I'm having a problem with my conpiler.
Below is what I typed but it is giving me
Can anybody help me?

7  parse error before `float'
10 `fltMoney' undeclared (first use this function)
10  (Each undeclared identifier is reported only once for each function it appears in.)
13 parse error before `>'
16 parse error before `>'
19  parse error before `>'
22  parse error before `>'
25  parse error before `>'
28 parse error before `>'
15  warning: unreachable code at beginning of switch statement
38  parse error before `return'


 //Bonus
 #include<iostream.h>
 #include<stdlib.h>
 int main()
 {
  float fltBonus
  float fltMoney
  int i;
  cout <<"Input amount collected ";
  cin >> fltMoney;
  switch(fltMoney)
           {
                  case > 500.0:
                         fltBonus = 0.1 * fltMoney;
                         break;
                  case > 400.0:
                         fltBonus = 0.09 * fltMoney;
                         break;
                  case > 300.0:
                         fltBonus = 0.08 * fltMoney;
                         break;
                  case > 200.0:
                         fltBonus = 0.07 * fltMoney;
                         break;
                  case > 100.0:
                         fltBonus = 0.06 * fltMoney;
                         break;
                  case > 50.0:
                         fltBonus = 0.02 * fltMoney
                         break;
                  default:
                         fltBonus = 0;
                         break;
            }
  cout << "\nBonus received" << fltBonus;
  cout <<endl;
  system ("PAUSE")
  return 0;
 }

Recommended Answers

All 9 Replies

Don't forget your semi-colons:

float fltBonus;
float fltMoney;

system ("PAUSE");
fltBonus = 0.02 * fltMoney;

And case statements look like this:
case 50.0:

EDIT: MrSpigot beat me to the semi-colon bit but the rest applies.

You are missing semi-colons in these lines:

float fltBonus
float fltMoney

Also you have > in your case statements. You need an if clause to do what you are trying to do.

Also, don't use #include<iostream.h> . Use #include <iostream> with a using namespace std; statement. Same for #include<stdlib.h> .

>>Same for #include<stdlib.h>
The standard file for the old stdlib.h is <cstdlib>

Brilliant guys, many thanks for your swift reply.I'm just down to one error.
Its saying there is no such file or directory. #include <stdlib>

//Bonus
#include <iostream>
#include <stdlib>
using namespace std;
int main()
{
float fltBonus;
float fltMoney;
int i;
cout <<"Input amount collected ";
cin >> fltMoney;
switch(fltMoney)

Read my post ( #4)
I told you that the header file is <cstdlib> and not <stdlib>

Did that, thanks. Still getting errors. How does this look.

//Bonus
 #include <iostream>
 #include <cstdlib>
  using namespace std;
 int main()
 {
  float fltBonus;
  float fltMoney;
  int i;
  cout <<"Input amount collected ";
  cin >> fltMoney;
  switch(fltMoney)
           {
                  case if >500.0:
                       then fltBonus = 0.1 * fltMoney;
                         break;
                  case if >400.0:
                       then  fltBonus = 0.09 * fltMoney;

This is not a valid statement:
case if >400.0:

Each case must be a specific value, not a range or condition. If you need a range, forget the switch and do it all with if statements.

Happy to help but this pretty basic stuff. I would recommend that you sit down with a C++ book and do some reading.

To the OP: Can you please post using code tags ?

I know you are right about that. Have book beside me right now.Deitel C++ How to Program. Just a novice at this stuff. Many thanks for your help. Hope to be able to be of assistance to community in the future. Under time pressure to finish assignment.

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.