English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

all right here is the deal, how do i fix this program? >>>

//This program will ask user to input two integers.
//main will call a user-defined function "GetSum" to return their sum.
//main will also call a system predefined function "pow" to get the square of sum.

#include
#include
using namespace std;

void Getsum(int);

int main ( )
{
int num1 = 0, num2 = 0, sum = 0, square = 0;

cout << "enter the first integer: ";
cin >> num1;
cout << "enter the second integer: ";
cin >> num2;

GetSum(num1, num2);
square = pow(sum);

cout << "Their sum is " << sum << endl;
cout << "The square of sum is " << square << endl;

return 0;
}

void GetSum(int A, int B)
{
int S = A + B;
return;
}

2006-10-31 16:52:12 · 2 answers · asked by biscuits 2 in Computers & Internet Programming & Design

2 answers

You had some pretty simple errors...
1) You spelled the Getsum function prototype differently than you did in the function call
2) You are passing a different number of parameters from the function prototype than in the function
3)Where does int A, and Int B get a value from? If the program would have worked you would have added whatever was stored in memory from A and B, since you didn't initialize them.
4)Void functions DONT return anything

I came up with a few fixes listed below, the error that you are getting from the pow(sum); line is very easily fixed, simply use the correct preprocessor directive...cmath didn't seem to work for me.


//This program will ask user to input two integers.
//main will call a user-defined function "GetSum" to return their sum.
//main will also call a system predefined function "pow" to get the square of sum.

#include
#include

using namespace std;

void GetSum(int num1, int num2);

int main ( )
{
int num1 = 0, num2 = 0, sum = 0, square = 0;

cout << "enter the first integer: ";
cin >> num1;
cout << "enter the second integer: ";
cin >> num2;

GetSum(num1, num2);
//square = pow(sum);

cout << "Their sum is " << sum << endl;
cout << "The square of sum is " << square << endl;

return 0;
}

void GetSum(int num1, int num2)
{
int S = num1 + num2;
return;
}
********************
Since I did not know the correct pre-processor directive, I did a minor re-write of your code, now function (now an int returning function) will return the value S.

//This program will ask user to input two integers.
//main will call a user-defined function "GetSum" to return their sum.
//main will also call a system predefined function "pow" to get the square of sum.

#include
#include

using namespace std;

int GetSum(int num1, int num2);

int main ( )
{
int num1 = 0, num2 = 0, sum = 0, square = 0;

cout << "enter the first integer: ";
cin >> num1;
cout << "enter the second integer: ";
cin >> num2;

GetSum(num1, num2);
//square = pow(sum);
sum = GetSum(num1,num2);
cout << "Their sum is " << sum << endl;
cout << "The square of sum is " << square << endl;
system("pause");
return 0;
}

int GetSum(int num1, int num2)
{
int S = num1 + num2;
return S;
}

2006-10-31 18:00:48 · answer #1 · answered by D 4 · 0 0

main changes to

...
cout << "Their sum is " << GetSum(num1,num2) << endl;
...



void GetSum(int A, int B)
{
int S = A + B;
return;
}

changes to

int GetSum(int A, int B) {
return A + B;
}

2006-10-31 17:02:26 · answer #2 · answered by WickedSmaht 3 · 0 0

fedest.com, questions and answers