GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 02-Mar-2004, 20:20
soulfly soulfly is offline
New Member
 
Join Date: Mar 2004
Posts: 8
soulfly is on a distinguished road
Question

Please Help, problems writing c program REVISED


CPP / C++ / C Code:
/*  Group Project pg 299, # 58
  <kbd>  written by:  
	3-3-04 

This program reads a list of integers from the keyboard and creates the following information:
find and print the sum and the average of the integers, find and print the largest and smallest
integer, print a boolean true or false if some of them are less than 20, print a boolean 
true or false if all of them are betrween 10 and 90.*/




#include <stdio.h>

/* Prototype Declarations*/

float totalNum (float totalintegers);
float findSum (float sum);
float findAverage (float avg);
float findLarge (float largest);
float findBool (float boolone , float booltwo);


int main (void)

{

/*Local Definitions*/

float num = 0;
float sum = 0;
float avg = 0;
float largest = 0;
float smallest = 0;
float boolone = 0;
float booltwo = 0;
float boolean = 0;
float totalintegers = 0;

/*Statememts*/

printf(" Please enter numbers: <return> : Enter 99999 to stop");
scanf("%f",&num);

do

{
	totalintegers = totalNum (totalintegers);
	sum = findSum (sum);
    avg = findAverage (avg);
	largest = findLarge (largest);
	boolean = findBool (boolone,booltwo);
}

while (num!=99999);


printf(" The number of integers is:              %f\n",totalintegers);
printf(" The sum of the integers is:            %f\n",sum);
printf(" The average of the intergers is:        %f\n",avg);
printf(" The smallest integer is:                %f\n",smallest);
printf(" The largest integer is:                 %f\n",largest);

if (boolone !=0)
     
     printf(" True, some of the integers are less than twenty\n");

else

     printf(" False, none of the integers are less than twenty\n");

if (booltwo!=0)
  
    printf(" True, all of the integers are between 10 and 90\n");

else

    printf(" False, none of the integers are between 10 and 90\n");

return 0;

}




float totalNum (float totalintegers)
{



	totalintegers ++;

return totalintegers;

}



float findSum (float sum , float num)
{



	sum = num + num;


return sum;

}



float findAverage (float avg)
{

float sum = 0;
float totalintegers = 0;

	avg = sum / totalintegers;

return avg;

}



float findLarge (float largest , float smallest)

{

float num = 0;




	if (num > num)

		largest = num;

	else

		smallest = num;

return largest , smallest;

}

float findBool (float boolone , float booltwo)
{
float num = 0;


	if (num < 20 )

		boolone = 1; 

	else

		boolone = 0;

	if (num > 10 && num < 90)

		booltwo = 1;

	else

		booltwo = 0;


return boolone , booltwo;

}
Last edited by dsmith : 02-Mar-2004 at 21:54.
  #2  
Old 02-Mar-2004, 20:36
soulfly soulfly is offline
New Member
 
Join Date: Mar 2004
Posts: 8
soulfly is on a distinguished road
I can compile this code but when i execute it I get the following error:


--------------------Configuration: 3rd group project - Win32 Debug--------------------
Linking...
3rd group project.obj : error LNK2001: unresolved external symbol "float __cdecl findLarge(float)" (?findLarge@@YAMM@Z)
3rd group project.obj : error LNK2001: unresolved external symbol "float __cdecl findSum(float)" (?findSum@@YAMM@Z)
Debug/3rd group project.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

3rd group project.exe - 3 error(s), 0 warning(s)
  #3  
Old 02-Mar-2004, 22:00
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,245
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
How many threads are you planning on creating for this one program? Three so far! Please continue posting questions about the same program in the first thread (and only) you start. And don't forget to surround your code (top and bottom) in [C] / [/C] tags
  #4  
Old 02-Mar-2004, 22:01
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Hi again soulfly.

A couple of things to keep in mind. Don't post duplicates threads please. Also, once you start a thread, just reply to it if it is the same topic. And lastly, when you post code, if you sorround it by [c] and [/c] it will highlight the code and make it much easier to read. Thanks.

Now on to the task at hand. Your errors are coming because you declare your functions as one thing, but then define them as something else. For example:
CPP / C++ / C Code:
float findLarge (float largest);
is your decleration, but when you define the function it now reads:
CPP / C++ / C Code:
float findLarge (float largest , float smallest)
That is not the same.

Also, you need to reread the other post I sent to you. C cannot pass back more than one value. Your statements of:
CPP / C++ / C Code:
return largest , smallest;
is not legal. You can only pass one variable back in a return statement.
  #5  
Old 03-Mar-2004, 11:44
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Here's a debugging suggestion (now that you say that your program compiles
successfully):

First make sure that you are reading each number OK.

That is, just after the scanf() statement put in a printf() statement
to print out its value, and see if it is what you entered.

Once you have verified correct data entry, proceed to the next step in your
logic.

Good luck!

Dave
  #6  
Old 03-Mar-2004, 12:18
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 4,720
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by davekw7x
Here's a debugging suggestion (now that you say that your program compiles
successfully):

First make sure that you are reading each number OK.

That is, just after the scanf() statement put in a printf() statement
to print out its value, and see if it is what you entered.

Once you have verified correct data entry, proceed to the next step in your
logic.

Good luck!

Dave


By the way, the program you posted here has several errors that prevent
successful compilation on any standard compiler. What compiler are you
using?


Dave
  #7  
Old 03-Mar-2004, 13:57
aaroncohn's Avatar
aaroncohn aaroncohn is offline
Regular Member
 
Join Date: Feb 2004
Location: Bay Area, CA.
Posts: 564
aaroncohn is a jewel in the roughaaroncohn is a jewel in the roughaaroncohn is a jewel in the rough
I just read the header of your code.. it says that this is a group project from a book... I'm just going to guess that this is an assignment for a class. I would strongly suggest that you start taking notes and paying more attention during lecture, as well as supplementing your studies with your book, because you are missing some of the fundamental basics of C programming. I could just as well point out every problem in that program and tell you exactly how to fix it and why it should be that way, but you probably wouldn't learn anything if I did that. So, talk to your instructor and ask for help on certain aspects of your code, or consult a book for syntax help. This forum responds much better to problems that require thinking. This is just a general syntax problem that you can figure out by studying. Look at dsmith's post for a couple rules about C programming, and davekw7x's post for a general tip on writing programs in C.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 2) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chaintech Geforce 5600 FX problems bartster74 Computer Hardware Forum 8 04-May-2004 13:16
Please Help, problems writing newbie c program soulfly C Programming Language 14 04-Mar-2004 15:16
compiling a program within another (C++) Siphiro C++ Forum 5 06-Feb-2004 15:35
error during program rjd72285 C++ Forum 0 11-Nov-2003 18:49
one program access another? dgoulston C++ Forum 1 07-Oct-2003 11:26

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 20:37.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.