2 variables minus

When I try to minus it, it wont compile and run. Whats wrong with the last part.

#include <iostream>

using namespace std;


int total(int a, int b, int c)
{
return a + b + c;
}

int main()
{
string name;
int age;
double average;

cout << "What is you're name? " << endl;
cin >> name;

cout <<"what is you're age? " << endl;
cin >> age;

cout << name << " is " << age << " years old." << endl;
int a;
int b;
int c;
cout <<"to find the total... " << endl;
cout << "enter your 1st number." << endl;
cin >> a;
cout << "enter your 2nd number." << endl;
cin >> b;
cout << "enter your 3rd number." << endl;
cin >> c;

cout << "You're total is " << total(a , b,c) << endl;
cout <<"Now i will minus your age from your total." << endl;

int agetotal;
agetotal = age -total;
cout <<"The answer is " << agetotal << endl;
return 0;



}
You should keep the value returned by function total in some variable and use it in calculation of agetotal.
how would i do that? please show me a example.

Last edited on
1
2
3
4
5
6
7
int totalval = total(a,b,c);  // keep track of the returned value in a variable

cout << "You're total is " << totalval << endl; // use that variable to print to the user
cout <<"Now i will minus your age from your total." << endl;

int agetotal;
agetotal = age - totalval;  // use that value to subtract 
Topic archived. No new replies allowed.