I have tried and tried to figure out what it is I am have wrong. I have an assignment to create a program that calculates employee's bonus. I think I pretty much have it, but I keep getting an error that I cant figure out and what the error is trying to tell me. If someone could please help I would really appreciate it.

#include <iostream>
#include <string>
using namespace std;

myfunc (int calc_bonus);

int main ( ) 
{
   string name;
   int total_sales, bonus;
	cin >> name;
	cin >> total_sales;
   int calc_bonus(int sales){
	int temp
          if (total_sales < 3001) temp = 0;
	   if (total_sales > 3000 && < 5001) temp = 50;
	   if (total_sales > 5000 && < 10000) temp = 100;
	   if (total_sales > 9999) temp = 250;
       return temp
}
       cout << “ name's bonus is ” << bonus << endl;
};
      //   Exit program.
   return 0;
}

Here is the error I got from the compiler

Line 21: error: stray '\342' in program
compilation terminated due to -Wfatal-errors.

Again, any assistance would be great! Thanks!

Edited 7 Years Ago by Nick Evan: Added code-tags. Always wrap your code in [code] ...code here... [/code] tags

You seem to be using a lousy code editor and have "fancy quotes" instead of the plain variety. After that you'll get more syntax errors to clean up, like this

int calc_bonus(int sales){

You need to learn how to declare, define, and call functions. So maybe take another look at your text?

Edited 7 Years Ago by Dave Sinkula: n/a

You seem to be using a lousy code editor and have "fancy quotes" instead of the plain variety. After that you'll get more syntax errors to clean up, like this

int calc_bonus(int sales){

You need to learn how to declare, define, and call functions. So maybe take another look at your text?

I am sure my compiler is not the best, its free. I dont know what is wrong with the line you pointed out... the error that the compiler I use had an issue with my cout line.

How to use functions :

1) Declare a prototype .

Ex :

//int is the return type
//calculateBonus is the function's name
//int number is its argument
// the semicolon " ; " means its a prototype
int calculateBonus(int number);

2) Give it a body outside of main :

ex :

int calculateBonus(int num)
{
    if( num < 100 ) return 10;
   else if(num < 1000 ) return 100;
   else return 1000;
}

3) Use it inside main :

int main()
{
    int bonus = calculateBonus(100);
  //more code

  return 0;
}

Here is an complete example :

#include<iostream>
using namespace std;

int calculateBonus(int num)
{
    if( num < 100 ) return 10;
   else if(num < 1000 ) return 100;
   else return 1000;
}

int main()
{
   int money = 10;
   int bonus= calculateBonus(money);
   cout<<"bonus = " << bonus << endl;
   return 0;
}

I didnt realize how my post pasted... I have to output the sales' person's name and their bonus. Here it is again...
/* calculate bonuses */ // This program calculates a salespersons bonus based on the amount of inputted sales.

#include <iostream>
#include <string>
using namespace std;

myfunc (int calc_bonus);

int main ( ) 
{
   string name;
   int total_sales, bonus;
	cin >> name;
	cin >> total_sales;
   int calc_bonus(int sales){
	int temp
          if (total_sales < 3001) temp = 0;
	   if (total_sales > 3000 && < 5001) temp = 50;
	   if (total_sales > 5000 && < 10000) temp = 100;
	   if (total_sales > 9999) temp = 250;
       return temp
}
       cout << “ ‘s bonus is ” << bonus << endl;
};
      //   Exit program.
   return 0;
}

Edited 7 Years Ago by Nick Evan: Added code-tags. Always wrap your code in [code] ...code here... [/code]

You need to change this line: cout << “ ‘s bonus is ” << bonus << endl; to: cout << " bonus is " << bonus << endl; without the fancy quotes, but with the plain old ones.


also: What Firstperson said!

Edited 7 Years Ago by Nick Evan: n/a

This question has already been answered. Start a new discussion instead.