473,395 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problems with a program that does two functions

can anyone help me I cant get this program to run, it errors during bugging! I thought I was pretty close to having it, but I can't get it! thanks!


//C++ Project 3:
//For your Project 3 Write a program that has two separate functions.
//One function will determine and return the smallest of three numbers
//and the other function will determine and return the average of three
//numbers. Both functions should return a value. This should be submitted
//in your Assignments folder. Please submit your work as a .cpp file
//attachment so that it does not lose the spacing/indentations. Your file
//should be named lastname1.cpp. For example, my program would be Jackson1.cpp.

#include <iostream>
using namespace std;
int main()
{
int num1, num2, num3, average;
cout << "Enter any three integers: ";
cin >> num1;
cin >> num2;
cin >> num3;
cout << "The three integers you entered are " << num1 << " , " << num2 << " and " << num3 << endl;
average = (num1 + num2 + num3)/3;
cout << "The average of the three integers" << endl;
cout << "you have entered is." << average << endl;
return 0;
}

{
int num1, num2, num3, min;
cout << "Please enter any three integer: ";
cin >> num1;
cin >> num2;
cin >> num3;
cout << "The three integers you entered are " << num1 << " , " << num2 << " and " << num3 << endl;
cout << "The number with the smallest value is ";
if (num1 < num2)
min = num1;
else
min = num2;
if (num3 < min)
min = num3;
cout << min << "." << endl;
int i;
cin >> i;
return 0;
}
Jan 10 '07 #1
3 1864
Banfa
9,065 Expert Mod 8TB
can anyone help me I cant get this program to run, it errors during bugging! I thought I was pretty close to having it, but I can't get it! thanks!
Do you mean it gives an error during compilation? Which I would expect it to do.

You have not defined 2 functions, you have defined 1 function, main, but then you have tried to define a second function but not declared it you have only given a function body.

Expand|Select|Wrap|Line Numbers
  1.  
  2. #include <iostream>   
  3. using namespace std;   
  4.  
  5. int main()  
  6.     <snipped>
  7. }
  8.  
  9. /* you need to declare the function here something like */
  10.  
  11. int MyFunction()
  12.     <snipped>
  13. }
  14.  
Jan 10 '07 #2
Thanks for the help, I had int main in the first time, but i guess because they both had the same name it was not compiling. I deleted it and forgot to change it! LOL It compiles now and again Thanks! However now I cant get both parts to run? Am I doing something wrong? The first part which averages the integers runs, but then the second part which should tell you which number is the smallest does not show up? Any Ideas? Thanks!!!!

//C++ Project 3:
//For your Project 3 Write a program that has two separate functions.
//One function will determine and return the smallest of three numbers
//and the other function will determine and return the average of three
//numbers. Both functions should return a value. This should be submitted
//in your Assignments folder. Please submit your work as a .cpp file
//attachment so that it does not lose the spacing/indentations. Your file
//should be named lastname1.cpp. For example, my program would be Jackson1.cpp.

#include <iostream>
using namespace std;
int main()
{
int num1, num2, num3, average;
cout << "Enter any three integers: ";
cin >> num1;
cin >> num2;
cin >> num3;
cout << "The three integers you entered are " << num1 << " , " << num2 << " and " << num3 << endl;
average = (num1 + num2 + num3)/3;
cout << "The average of the three integers" << endl;
cout << "you have entered is " << average << endl;

}
int main2()
{
int num1, num2, num3, min;
cout << "Please enter any three integer: ";
cin >> num1;
cin >> num2;
cin >> num3;
cout << "The three integers you entered are " << num1 << " , " << num2 << " and " << num3 << endl;
cout << "The number with the smallest value is ";
if (num1 < num2)
min = num1;
else
min = num2;
if (num3 < min)
min = num3;
cout << min << "." << endl;
int i;
cin >> i;
return 0;
}
Jan 11 '07 #3
Banfa
9,065 Expert Mod 8TB
I think you have mis-interpreted your question (but i also think it is badly worded so may be you should check with your lecturer).

I think that the structure this program requires is

Expand|Select|Wrap|Line Numbers
  1. /* Include relevent headers */
  2.  
  3.  
  4. /* Predeclare functions in use */
  5. static int Average(int,int,int);
  6. static int Smallest(int,int,int);
  7.  
  8.  
  9. int main()
  10. {
  11.     int x, y, z;
  12.     int average;
  13.     int smallest;
  14.  
  15.     /* Code to get 3 integers x, y and z */
  16.  
  17.     /* Call functions to get statistics */
  18.     average = Average(x, y, z);
  19.     smallest = Smallest(x, y, z);
  20.  
  21.     /* Output data x, y, z, average and smallest */
  22. }
  23.  
  24. static int Average(int x, int y, int z)
  25. {
  26.     /* code to calculate average of 3 integers x, y and z */
  27.  
  28.    return <result>;
  29. }
  30.  
  31. int Smallest(int x, int y, int z)
  32. {
  33.     /* code to calculate smallest of 3 integers x, y and z */
  34.  
  35.    return <result>;
  36. }
  37.  
i.e. 1 main function geting the data and outputing the results calling 2 functions that each calculate 1 statistic and return it.

Note this is only the structure however since you already have all the functional code required I figure you can probably manage to get it working from here.
Jan 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: jblazi | last post by:
I should like to search certain characters in a string and when they are found, I want to replace other characters in other strings that are at the same position (for a very simply mastermind game)...
5
by: Ryan Faulkner | last post by:
Hi, Im having a few problems with virtual functions (Im using the Visual C++ environment by the way). I have a base class with three virtual functions and a derived class with a single new...
6
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which...
3
by: Steven T. Hatton | last post by:
Scroll to the bottom and read the last part first. I've been trying very diligently to 'modularize' the code from TC++PL3E found here: http://www.research.att.com/~bs/matrix.c I keep getting...
9
by: Daniel Moree | last post by:
I'm using MS VC++ 6.0 I'm working on a big project. I've currently have several files for this project. Here's the problem. I have one header file phead.h I have two code files main.cpp and...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
2
by: Mike | last post by:
Hi, I am new to C and having problems with the following program. Basically I am trying to read some files, loading data structures into memory for latter searching. I am trying to use structres...
9
by: =?Utf-8?B?SG93YXJkIFNtaXRo?= | last post by:
I am using VC++ 6.0 (with SP5 installed). When using WinXP this is with SP2 installed. I am developing an instrumentation system comprising a set of networked PCs connected using TCP/IP TCP links....
10
by: Cliff | last post by:
Greetings, I have been trying to teach myself C++ over the past few weeks and have finally came across a problem I could not fix. I made a simple program that prints out a square or rectangle...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.