There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
new to c++


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
daybo's Avatar
Senior Member with 170 posts.
 
Join Date: Aug 2001
Location: North Carolina
13-Mar-2003, 09:57 PM #1
new to c++
i am familiar with visual basic but just getting into c++, and to say the least its different. i get the following error and sure how to fix after hours. very simple program but leave it up to me to make it hard.
Error:
C:\Documents and Settings\C++\project1.cpp(10) : error C2447: missing function header (old-style formal list?)
Error executing cl.exe.

can anyone teel me where i went wrong from my code? i really appreciate it!
#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int maximum(int, int, int,int,int);
int minimum(int, int, int,int,int);

{

int num1;
int num2; //dimension variables
int num3;
int num4;
int num5;
int sum;
int avg;
int prod;
int min;
int max;


cout << "Enter 1st #\n"; //Prompt
cin >> num1; // read integer

cout << "Enter 2nd #\n"; //prompt
cin >> num2; //read integer

cout << "Enter 3rd #\n"; //prompt
cin >> num3; //read integer

cout << "Enter 4th #\n"; //prompt
cin >> num4; //read integer

cout << "Enter 5th #\n"; //prompt
cin >> num5; //read integer

sum = num1 + num2 + num3 + num4 + num5; //assign result to sum
avg = sum / 5;
prod = num1 * num2 * num3 * num4 * num5;

min = minimum(num1, num2, num3, num4, num5);
max = maximum(num1, num2, num3, num4, num5);

cout << "Sum is " << sum << std::endl; //print sum
cout << "Average is " << avg << std::endl; //print sum
cout << "Product is " << prod << std::endl; //print sum


return 0;

}
__________________
daybo
the 100% Mixed MuLaTtO
juryu's Avatar
Junior Member with 18 posts.
 
Join Date: Feb 2003
Location: Rio
14-Mar-2003, 09:51 PM #2
Someone correct me if I'm wrong because I am not really a C++ programmer but only C, but let's see what I can do...

First of all I think your function declarations
int maximum(int, int, int,int,int);
Need to give names to the int's they are receiving for example,
int maximum(int a, int b, int c, int d, int e);

And I assume the functions are written somewhere else.

Then the thing that starts at the { is where you want your program to start? Then you need to write
void main()
{
instead of just
{

Let me know if it helped...
AlbertB's Avatar
Distinguished Member with 2,432 posts.
 
Join Date: Nov 2002
Location: Hampshire, UK
15-Mar-2003, 12:25 AM #3
daybo
Quite right juryu, you should have your programs execution starting point in a "main" function. In your case, as you have included "return 0" at the end of that function, it should be an "int main" type to return an int value of 0.

You should not need to give specific parameter names in the function prototypes, they only need the parameter type to be specified at that stage. You would see the full named parameter list at the definition and function call stages.

Whose version of C++ are you using daybo? Your #include and using lines will need looked at too, (#include [stdio.h], (should be angle brackets here not square but it confuses the site html), and use printf not cout, and scanf not cin).

This seems to work:


#include [stdio.h] // remember these must become angled brackets in your program

int maximum(int, int, int, int, int);
int minimum(int, int, int, int, int);

int main ()
{

int num1 =0; // initialise all variables
int num2 =0;
int num3 =0;
int num4 =0;
int num5 =0;
int sum =0;
int avg =0;
int prod =0;
int min =0;
int max =0;

/*
printf ("%d\n", sum) places the value of the variable "sum" into the output text in place of %d, a signed integer.

scanf("%d", &num1) reads a value into num1. Note the &, scanf must be passed the address of num1, not just its variable name. Call by reference not call by value. It replaces %d with the value entered at the keyboard.
*/

printf ("Enter 1st #\n"); //Prompt
scanf("%d", &num1) ; //read integer

printf ("Enter 2nd #\n"); //Prompt
scanf("%d", &num2) ; //read integer

printf ("Enter 3rd #\n"); //Prompt
scanf("%d", &num3) ; //read integer

printf ("Enter 4th #\n"); //Prompt
scanf("%d", &num4) ; //read integer

printf ("Enter 5th #\n"); //Prompt
scanf("%d", &num5) ; //read integer

sum = num1 + num2 + num3 + num4 + num5; //assign result to sum
avg = sum / 5;
prod = num1 * num2 * num3 * num4 * num5;

printf ("Sum is:\n"); //Prompt
printf ("%d\n", sum); //Prompt
printf ("Average is:\n"); //Prompt
printf ("%d\n", avg); //Prompt
printf ("Product is:\n"); //Prompt
printf ("%d\n", prod); //Prompt


// min = minimum(num1, num2, num3, num4, num5); These functions have not yet been written and they
// max = maximum(num1, num2, num3, num4, num5); will cause an error on build if not commented out.
return 0;

}



Your output as things stand will give the sum and product accurately, but the average will be truncated to an integer! Your next task is to make changes so that it is expressed as a floating point decimal. Don't worry about making it hard, C++ will do that for you very easily in my opinion.

Liked your attitude towards "occupation", same thinking here!
__________________
1. "I make no personal claim to the truth, only the right to seek it, prove it in argument, and to be wrong many times in order to reach it."

2. "We have made a cage of words and placed our God inside, as boys trap a cricket, to make him sing for us alone."

Galileo Galilei

Last edited by AlbertB : 15-Mar-2003 01:16 AM.
juryu's Avatar
Junior Member with 18 posts.
 
Join Date: Feb 2003
Location: Rio
15-Mar-2003, 11:43 AM #4
Thanx Albert for correcting me on the parameter list thing,
But why shouldn't he use cin and cout? I mean, I use scanf and printf, but if he wants to program in C++, I think people tend to use cin and cout... At least my friends who program in C++ use that.
daybo's Avatar
Senior Member with 170 posts.
 
Join Date: Aug 2001
Location: North Carolina
15-Mar-2003, 03:16 PM #5
that really helped alot. thanX!
AlbertB's Avatar
Distinguished Member with 2,432 posts.
 
Join Date: Nov 2002
Location: Hampshire, UK
15-Mar-2003, 04:41 PM #6
No you're quite right juryu, perhaps I shouldn't have steered daybo towards printf() and scanf() but I thought that as he said he was just getting into C++ from Vis Basic it would be a useful exercise to play with the functional approach, to explore what formatting options etc it offered, as he already had knowledge of the cout cin approach.

The cout cin approach is perfectly valid and is ultimately the better faster option. I considered that simple console applications are not going to be daybo's ultimate aim and any knowledge gained is to his advantage. I should have approached it the other way around, dealt with the cout cin problem, and maybe then mentioned printf scanf. Criticism taken on board. Sorry daybo, juryu is right. Here is a solution of your problem in your own form.

This time I have inserted a global "using" declaration for the namespace std rather than specifying each object individually. You can then use anything contained in the std namespace without any further qualification.



#include [iostream] // replace [ ] with angled equivalents, html does not like to see them!

using namespace std; // note the inclusion of this declaration line!

// int maximum(int, int, int, int, int); save them for later. They are
// int minimum(int, int, int, int, int); only a complication at this time.

int main ()
{

float num1 =0; // initialise all variables.
float num2 =0; // I have made them all
float num3 =0; // floats to give an accurate
float num4 =0; // unrounded value of Average.
float num5 =0; // You can now enter values
float sum =0; // as integers or decimals.
float avg =0;
float prod =0;

float min =0;
float max =0;

cout << "Enter 1st #: " ;
cin >> num1 ;

cout << "Enter 2nd #: " ;
cin >> num2 ;

cout << "Enter 3rd #: " ;
cin >> num3 ;

cout << "Enter 4th #: " ;
cin >> num4 ;

cout << "Enter 5th #: " ;
cin >> num5 ;

sum = num1 + num2 + num3 + num4 + num5;
avg = sum / 5;
prod = num1 * num2 * num3 * num4 * num5;

// min = minimum(num1, num2, num3, num4, num5); These functions have not yet been written and they
// max = maximum(num1, num2, num3, num4, num5); will cause an error on build if not commented out.

cout << endl << "Sum is: " << sum << endl ;
cout << endl << "Average is: " << avg << endl ;
cout << endl << "Product is: " << prod << endl << endl ;

return 0;

}


Oh and nearly forgot, as you had already inserted using directives on cout, cin and endl you did not need to use endl as "std::endl" in your final cout statements. The current "using namespace std" makes these issues all academic.
__________________
1. "I make no personal claim to the truth, only the right to seek it, prove it in argument, and to be wrong many times in order to reach it."

2. "We have made a cage of words and placed our God inside, as boys trap a cricket, to make him sing for us alone."

Galileo Galilei

Last edited by AlbertB : 15-Mar-2003 04:59 PM.
anthony_czyk's Avatar
Junior Member with 3 posts.
 
Join Date: Mar 2003
Location: Washington
21-Mar-2003, 02:01 PM #7
Smile make some changes
right off teh bat, change your std:ut, in to using namespace::std, it is much more concise and robust, as for the numbers you are entering, use an array and pass everything into a function by reference
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 10:34 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.