Here is another shot at it. It all most complier but falls short . still I know it doesn't mean its right. thanks for the help so far.

Attachments
/********************************************************
*  Name:           template
*  Author:         Francis Waldron     
*  Date due:       25/09/06
*  Description:    basic C++ programming 
**********************************************************/

/***************************
*     libraries
****************************/
#include <iostream>            // needed for Cin and Cout
using namespace std;

/************************************
*     defines
*************************************/
#define  PI  3.14159

/*************************************
*     function prototype
*************************************/
int intSum(int ,int );
int intDiff(int , int );
int intProd(int , int );
double Quot(int , int );
/************************************
*      global variables
*************************************/
 
    
  


int main()
{
    int num1;
    int num2;
    int s=0;
    int d=0;
    int p=0;
    double q=0.0;
        
    cout << " enter first number:  \n";
    cin >>num1;
    cout << " enter second number:  \n";
    cin >> num2; 
    s = intSum(num1,num2);
    cout << " The sum of two numbers is" << s << "\n";

    d = intDiff(num1,num2);
    cout << " The difference of the two numbers is" << d <<"\n";
    
    p = intProd(num1,num2);
    cout << "The Product of two numbers is"<< p <<"\n";
    
    q = Quot(num1,num2);
    cout << " The quoent of two numbers is"<< q <<"\n";
    
}
int intSum( int num1, int num2)
{
    int s=0;
    s = num1 + num2;
    return s;
} 
int inDiff(int num1, int num2)
{
    int d=0;
    d = num1 - num2;
    return d;
}
int inProd(int num1, int num2)
{
    int p = 0;
    p = num1 * num2; 
    return p;
}
double Quot(int num1, int num2)
{
       double q = 0.0;
       q = num1 % num2;
       return q;
} 

     system("pause");
     }
     return 0;

two problems I can see without even compiling it.

1. main() should return an integer. I know it returns 0 if no return is specified, but you should expeclitly return a value anyway.

system("pause");
     }
     return 0;

2. Above is not inside any function.

>>#define PI 3.14159
you should declare this as a const. defines are fround upon in c++ programs.

const float PI = 3.14159;

I tried all this stuff still didn't work.


two problems I can see without even compiling it.

1. main() should return an integer. I know it returns 0 if no return is specified, but you should expeclitly return a value anyway.

system("pause");
     }
     return 0;

2. Above is not inside any function.

>>#define PI 3.14159
you should declare this as a const. defines are fround upon in c++ programs.

const float PI = 3.14159;

I allready mentioned this in your other thread :

system("pause");
} 
return 0;

This isn't in main() nor in another function. Put this before the closing brracket from main(){}

cout << " The quoent of two numbers is"<< q <<"\n";
 
//put it HERE and remove the bracket in marked in blue
 
}
int inProd(int num1, int num2)

This should be intProd,with a t

int inDiff(int num1, int num2)

This should be intDiff, with a t

Edited 6 Years Ago by Nick Evan: n/a

I've commented out your mistakes and placed the correct bits where necessary. I also commented what you had wrong. Its mostly syntax errors, nothing too bad, just keep a eye out for these things. Also, always make sure your main() returns a 0. You had this code, but right down the bottom of your program!!

#include <iostream>            // needed for Cin and Cout
using namespace std;

//#define  PI  3.14159 // don't need this

int intSum(int ,int );
int intDiff(int , int );
int intProd(int , int );
double Quot(int , int );

int main()
{
    int num1;
    int num2;
    int s=0;
    int d=0;
    int p=0;
    double q=0.0;
        
    cout << " enter first number:  \n";
    cin >>num1;
    cout << " enter second number:  \n";
    cin >> num2; 
    s = intSum(num1,num2);
    cout << " The sum of two numbers is" << s << "\n";

    d = intDiff(num1,num2);
    cout << " The difference of the two numbers is" << d <<"\n";
    
    p = intProd(num1,num2);
    cout << "The Product of two numbers is"<< p <<"\n";
    
    q = Quot(num1,num2);
    cout << " The quoent of two numbers is"<< q <<"\n";
    
    system("pause"); // placed this here, it was at the end of the program
    return 0;         // placed this here, it was at the end of the program
}
int intSum( int num1, int num2)
{
    int s=0;
    s = num1 + num2;
    return s;
} 
//int inDiff(int num1, int num2) // placed a 't' in intDiff
int intDiff(int num1, int num2)
{
    int d=0;
    d = num1 - num2;
    return d;
}
//int inProd(int num1, int num2)
int intProd(int num1, int num2) // placed a 't' in intProd
{
    int p = 0;
    p = num1 * num2; 
    return p;
}
double Quot(int num1, int num2)
{
       double q = 0.0;
       q = num1 % num2;
       return q;
} 

// the bit below shouldn't be here, should be at the end of main
/*
     system("pause");
     }
     return 0;
*/

Also, check this version out. It uses less variables and is cleaner and easier to understand. Study this and see the differences. Then make your decision as which road to take, good luck! ;)

#include <iostream>

using namespace std;

// const double PI = 3.14159; // don't need this

int intSum(int, int);
int intDiff(int, int);
int intProd(int, int);
double Quot(int, int);

int main()
{
    int num1;
    int num2;
        
    cout << "Enter first number: \n";
    cin >> num1;
    cout << "Enter second number: \n";
    cin >> num2;
    
    cout << "The sum of two numbers is " << intSum(num1,num2) << "\n";
    cout << "The difference of the two numbers is " << intDiff(num1,num2) <<"\n";    
    cout << "The Product of two numbers is "<< intProd(num1,num2) <<"\n";    
    cout << "The quoent of two numbers is "<< Quot(num1,num2) <<"\n";

    return 0;
}

int intSum(int num1, int num2)
{
    return (num1 + num2);
} 

int intDiff(int num1, int num2)
{
    return (num1 - num2);
}

int intProd(int num1, int num2)
{
    return (num1 * num2);
}

double Quot(int num1, int num2)
{
    return (num1 % num2);
}

>Also, always make sure your main() returns a 0.

Why? Pray tell?

It is standard convention throughout the IT industry for programs to return 0 when it exits normally, or some other value to indicate an error occurred. This allows other programs to check the status of the program and take appropriate action if necessary.

int main() is used to return 0 at the end. This 0 is returned to the Operating system to denote that the function main() - which is the only function called by the operating system and that's why its so special - has completed successfully. Always use int main() and return 0 at the end of it. Dont use void

int main() is used to return 0 at the end. This 0 is returned to the Operating system to denote that the function main() - which is the only function called by the operating system and that's why its so special - has completed successfully. Always use int main() and return 0 at the end of it. Dont use void

No I always use int main, but I don't always write return 0; at the end. It still works, why? Explain.


Here's a quote from 'ere

http://www.research.att.com/~bs/bs_faq2.html#void-main

In C++, main() need not contain an explicit return statement. In that case, the value returned is 0, meaning successful execution. For example: 

	#include<iostream>

	int main()
	{
		std::cout << "This program returns the integer value 0\n";
	}

>>It still works, why? Explain.
Is that a rhethorical question? you already answered it.

Oh I thought sumone was gonna enlighten me. :sad: Preferably someone who doesn't need a zimmer frame to walk. :cheesy:

This article has been dead for over six months. Start a new discussion instead.