so i made this program with a function call and definition and i keep having problems with the call function and i get error C2059: syntax error : 'return' when i build my program.

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int math (double cartons, double totalcost, double totalprofit, double milkprofit, double cost);
int main() 
{
int math;
char cartons,totalcost,totalprofit,milkprofit,cost;
 math= cartons + totalcost + totalprofit + milkprofit + cost;
 return (0); 
}

int math()
{

char ans = 'y';
bool quad_answer = false;
do 
{
double LitersMilkProduce;
double cartons, totalcost, totalprofit, milkprofit, cost;
 const double LITERCOST(0.37), CARTONPROFIT(0.27), LITERS_PER_CARTONS= (3.78);
cout << "Enter the total number of liters: ";
cin >> LitersMilkProduce;
cartons = LitersMilkProduce / LITERS_PER_CARTONS;
totalcost = LitersMilkProduce * LITERCOST;
totalprofit = LITERCOST * CARTONPROFIT;
cout << "The total number of liters = " << LitersMilkProduce << endl;
cout << fixed << showpoint<< setprecision(2) <<fixed <<  "Amount of cartons = " << cartons <<endl;
cout << "cost of milk is = ";
cin >> LitersMilkProduce ;
cost = LitersMilkProduce * LITERCOST;
cout << "profit from milk is =";
cin >> LitersMilkProduce;
milkprofit = LitersMilkProduce * CARTONPROFIT;
if (quad_answer) cout << endl;
cout << "Continue (y/n)? ";
cin  >> ans;
while (ans == 'y');
}
return 0;
};

Recommended Answers

All 7 Replies

On line 41, while should be on the other side of the closing brace, like this: } while(ans == 'y'). Fix that and see if that corrects the problem. Also, the closing brace for main() doesn't have a ";" after it. Remove that too.

It works now but now, but now i get these warings in line 11, i don't know if i called and defined my function correctly
cpp(11): warning C4700: uninitialized local variable 'cartons' used
cpp(11): warning C4700: uninitialized local variable 'totalcost' used
cpp(11): warning C4700: uninitialized local variable 'totalprofit' used
cpp(11): warning C4700: uninitialized local variable 'milkprofit' used
cpp(11): warning C4700: uninitialized local variable 'cost' used

That is just warning you that the variables that you are using have not been asigned any values. They contain only junk values that just happen to be in memory at that time. Why are you adding them up, as though you expect some kind of useful result? Or do you think that math will now equal the sum of those variables forever more? It doesn't work that way - math will equal the sum of those variables only as they exist now, and when they cahnge it will not reflect again in math.

i was try to define the function int math, is their a different way to deifne them

The function isn't called "int" math - it's just called math() (which happens to return an int.) So in your program, you now have a function called math and a variable of type int called math (line 9). You can't have both with the same name except under special circumstances. So you need to remove int math on line 9.

You are supposed to do math() not int math; when you call the function

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.