im having trouble with the function "double calcprofit(double amount2)"

#include <iostream>
#include <string>
#define profit .80
#define NR .90
#define RO .65
#define SN .40
#define SO .20
using namespace std;

//prototype
double calcprofit(double, int);
double calcnumbooks(double, double);
void output(double);



int main()

{
char letter1;
char letter2;
string isbn;
double price;
int enroll;
double amount1;
double amount2;




cout << "Enter book number: ";
cin >> isbn;


cout << "Enter price per copie: ";
cin >> price;

if (price < 0)
{
cout << "IMPROPER VALUE!" << endl;
system("pause");
exit(1);
}




cout << "Enter expected class enrollment: ";
cin >> enroll;

if (enroll < 0)
{
cout << "IMPROPER VALUE!" << endl;
system("pause");
exit(1);
}




cout << "Enter 'R' if required or 'S' if suggested: ";
cin >> letter1;
letter1 = toupper(letter1);cout <<static_cast<char>(toupper(letter1)) << endl;

if (isdigit(letter1))
{
cout << "YOU HAVE ENTERED A DIGIY!" << endl;
system("pause");
exit(2);
}




cout << "Enter 'N' if new or 'O' if not a new text: ";
cin >> letter2;
letter2 = toupper(letter2);cout <<static_cast<char>(toupper(letter2)) << endl;

if (isdigit(letter2))
{
cout << "YOU HAVE ENTERED A DIGIT!" << endl;
exit(3);
}


amount2 = calcprofit(amount2, enroll);
amount1 = calcnumbooks(enroll, price);
output(amount2);

system("pause");
return 0;
}

double calcprofit(double amount2, int enroll)

{
char letter1;
char letter2;
double amount2;




if(letter1 == 'R' && letter2 == 'N')
{amount2 = enroll * NR;}
else
if (letter1 =='R' && letter2 == 'O')
{amount2 = enroll * RO;}
else
if(letter1 == 'S' && letter2 == 'N')
{amount2 = enroll * SN;}
else
if(letter1 == 'S' && letter2 == 'O')
{amount2 = enroll * SO;}






return amount2;
}

double calcnumbooks(double enroll, double price)
{
double tbooks;

tbooks = enroll * price;


return tbooks;

}

void output(double amount1)
{


cout << "total: " ;

return;
}
the out put has to look like this:

Enter book number: 0755798652
Enter price per copy: 34.98
Enter expected class enrollment: 31
Enter 'R' if required or 'S' if suggested: r
Enter 'N' if new or 'O' if not a new text: O

ISBN: 0755798652
Copies Needed: 20
Profit: $ 139.92

Last edited on
First off surround the text of code with {code} and {/code} except use square brackets [] instead of curly braces {} to make it easier to read.

Also, be a bit more descriptive about your problem. It looks like your issue is scope, but that's a guess bc you aren't explaining the issue you are having. Letter1 and letter2 in

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

double calcprofit(double amount2, int enroll)

{ 
char letter1;
char letter2;
double amount2;

if(letter1 == 'R' && letter2 == 'N')
{amount2 = enroll * NR;}
else
if (letter1 =='R' && letter2 == 'O')
{amount2 = enroll * RO;}
else
if(letter1 == 'S' && letter2 == 'N')
{amount2 = enroll * SN;}
else
if(letter1 == 'S' && letter2 == 'O')
{amount2 = enroll * SO;}

return amount2;

}


Have no values. They are not the same variables as the ones in the main. You need to either make them global variables to the file or pass them as arguments to the function.
Topic archived. No new replies allowed.