I am having a problem with my program. We are supposed to ask for two numbers as input then half the larger and double the smaller. If the larger is odd then the smaller is added to an accumulator.

My problem lies (i'm guessing) somewhere in the functions.

Here is my code and below is my compile error.

/* Program Name:multiplication.cpp

   Description: Program does reverse multiplication

   Name:Scott Streit			Class No.: 4467
   Date:11/09/09			 	VisualC++
*/
//********************************** Includes
#include <cfloat>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <sstream>

#define cls system("cls")
#define frz system("pause");
#define yl  system("color 0e");

using namespace std;

//********************************** Type definitions
ofstream print("i:\\c++\\multiplication.txt");
//********************************** Function Prototypes
void input(int &nnum1, int &nnum2);
void findbig(int nnum1,int nnum2, int &bbig,int &ssmall);
void math(int bbig, int ssmall, int &ttotal);
void display();
//********************************** Main Function


int main()
{
	time_t t;
	time(&t);
	yl;
	cls;
	int num1, num2, big, small;
	int total=0;
		
	input(num1, num2);
	findbig(num1, num2, big, small);
	math(big, small, total);
	display();

      
	frz;
	return 0;
} // end of main function

//********************************** Function Definitions
void input(int &nnum1, int &nnum2)
{
	cout<<"Please enter your first number: ";
	cin>>nnum1;
	cout<<"Please enter your second number: ";
	cin>>nnum2;
}//end input

void findbig(int  nnum1, int nnum2,int bbig, int ssmall)
{
	if(nnum1>nnum2)
	{
		bbig=nnum1;
		ssmall=nnum2;
	}
	else
	{
		bbig=nnum2;
		ssmall=nnum1;
	}
	cout<<bbig<<"\n";
}//end findbig


void math(int bbig, int ssmall, int ttotal)
{
	ttotal=0;
	
	while (bbig!=0)
	{
		if (bbig%2==0)
		{
			(bbig/2);
			(ssmall*2);
		}//end if
		else
		{
			ttotal+=ssmall;
			(bbig/(2));
			(ssmall*(2));
		}//end else
	}//end while
			
	cout<<(bbig*ssmall)<<"\n";
	cout<<ttotal<<"\n";
}//end math

void display()
{
	cout<<"at display\n";
}//end display

Here is the compiler error.
1>------ Build started: Project: multiplication, Configuration: Debug Win32 ------
1>Compiling...
1>multiplication.cpp
1>i:\c++\multiplication\multiplication\multiplication.cpp(45) : error C2062: type 'char' unexpected
1>i:\c++\multiplication\multiplication\multiplication.cpp(49) : error C2062: type 'char' unexpected
1>i:\c++\multiplication\multiplication\multiplication.cpp(50) : error C2062: type 'char' unexpected
1>Build log was saved at "file://i:\c++\multiplication\multiplication\Debug\BuildLog.htm"
1>multiplication - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Recommended Answers

All 3 Replies

The problem is #define small char . You can't do this: int char , which is what you are doing then you say int small;

ok fixed one problem and created another.

here is my new error.

1>multiplication.obj : error LNK2019: unresolved external symbol "void __cdecl math(int,int,int &)" (?math@@YAXHHAAH@Z) referenced in function _main
1>multiplication.obj : error LNK2019: unresolved external symbol "void __cdecl findbig(int,int,int &,int &)" (?findbig@@YAXHHAAH0@Z) referenced in function _main
1>I:\c++\multiplication\Debug\multiplication.exe : fatal error LNK1120: 2 unresolved externals
1>Build log was saved at "file://i:\c++\multiplication\multiplication\Debug\BuildLog.htm"
1>multiplication - 3 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

//********************************** Includes
#include <cfloat>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cctype>
#include <iomanip>
#include <cmath>
#include <fstream>
#include <string>
#include <ctime>
#include <conio.h>
#include <windows.h>
#include <sstream>

#define cls system("cls")
#define frz system("pause");
#define yl  system("color 0e");

using namespace std;

//********************************** Type definitions
ofstream print("i:\\c++\\multiplication.txt");
//********************************** Function Prototypes
void input(int &nnum1, int &nnum2);
void findbig(int nnum1,int nnum2, int &bbignum,int &ssmallnum);
void math(int bbig, int ssmall, int &ttotal);
void display();
//********************************** Main Function


int main()
{
	time_t t;
	time(&t);
	yl;
	cls;
	int num1, num2, bignum, smallnum;
	int total=0;
		
	input(num1, num2);
	findbig(num1, num2, bignum, smallnum);
	math(bignum, smallnum, total);
	display();

      
	frz;
	return 0;
} // end of main function

//********************************** Function Definitions
void input(int &nnum1, int &nnum2)
{
	cout<<"Please enter your first number: ";
	cin>>nnum1;
	cout<<"Please enter your second number: ";
	cin>>nnum2;
}//end input

void findbig(int  nnum1, int nnum2,int bbignum, int ssmallnum)
{
	if(nnum1>nnum2)
	{
		bbignum=nnum1;
		ssmallnum=nnum2;
	}
	else
	{
		bbignum=nnum2;
		ssmallnum=nnum1;
	}
	cout<<bbignum<<"\n";
}//end findbig


void math(int bbignum, int ssmallnum, int ttotal)
{
	ttotal=0;
	
	while (bbignum!=0)
	{
		if (bbignum%2==0)
		{
			(bbignum/2);
			(ssmallnum*2);
		}//end if
		else
		{
			ttotal+=ssmallnum;
			(bbignum/(2));
			(ssmallnum*(2));
		}//end else
	}//end while
			
	cout<<(bbignum*ssmallnum)<<"\n";
	cout<<ttotal<<"\n";
}//end math

void display()
{
	cout<<"at display\n";
}//end display

Match your prototypes with function signatures.

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.