473,796 Members | 2,603 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Modifying a program to incorporate functions. LOST!!

3 New Member
First, I need to rewrite the program to incorporate functions. And there should be a value returning function that returns an int that the user entered. It will be called 5 times, once for each integer input.

After I compile the program, I need to modify the program again and replace the output statements with a call to a non-value returning function PrintAvg( ) that takes one parameter which is the calculated average. The function should print the avg to the screen just as the main( ) did originally.

I'm lost on how to complete these steps, I need some help on where to start, and some kind of an example to get me going. Thanks!

Here is the program below that I have originally made (and needs to be modified):

#include <iostream>

using namespace std;

int main(void)
{
int num1;
int num2;
int num3;
int num4;
int num5;
float avg;

cout << "Please enter a number: ";
cin >> num1;
cout << "Please enter a number: ";
cin >> num2;
cout << "Please enter a number: ";
cin >> num3;
cout << "Please enter a number: ";
cin >> num4;
cout << "Please enter a number: ";
cin >> num5;
avg = (num1 + num2 + num3 + num4 + num5)/5.0;
cout << "The average is " << avg << endl << endl; return 0;
}
Oct 15 '07 #1
1 1404
weaknessforcats
9,208 Recognized Expert Moderator Expert
Forget this problem.
Instead, write a program that calls a function that displays your name.

Based on that experience, try this problem again.

BTW: A little textbook reading won't hurt at all.
Oct 15 '07 #2

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

Similar topics

10
10650
by: Vince | last post by:
The following is code for the classic tortoise and hare C assignment. I am posting this for educational purposes only. Please do not plagiarize as comp sci instructors regularly read newsgroups. However, this program does help one learn about arrays and pointers. #include<stdio.h> #include<stdlib.h> #include<time.h>
2
1893
by: Roger Webb | last post by:
Hey. Is there a way to attach a satellite assembly to a specific programs' App.Config File? I have some assembly functions that get used in multiple programs... each configured in its own way. If I pass them in as parameters, then I cant update them. Anyone have an idea?? - Roger
8
2008
by: Dougal Fair | last post by:
I'm writing a VB.NET application, and I have a lot of general-purpose utility functions that need to be available throughout the program (like functions that perform standard date conversions peculiar to my app, etc.) and some global data values (i.e. the start and end dates of a billing period). I have gathered them all into an object and would like to make that object a global variable - instantiate it once and then be able to...
21
2556
by: asif929 | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to run, However, i simply created this program in arrays and it runs good except i cant figure out how to compute the standard deviation. The coding is below. Any help will be appreciated. 1) The Program will prompt the user for six grades to be...
1
3564
by: sparkid | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to run, However, i simply created this program in arrays and it runs good except i cant figure out how to compute the standard deviation. The coding is below. Any help will be appreciated. 1) The Program will prompt the user for six grades to be...
1
1931
by: gdarian216 | last post by:
I am reading in different names and scores from a file. I have created a struct that is made up of arrays and a string. Im tring to but the string and scores in the correct array by using a function. I am having trouble and im stuck if anyone can provide some insight I would appreciate it. this is what i have so far..... #include <iostream> #include <string> #include <vector> #include <fstream>
1
1223
by: Sleepwalker817 | last post by:
Hello, I need some help with the program included below. 174 lines of code removed - please read the posting guidelines about posting only the RELEVANT section of code I need to alter this program so that it uses at least three "non-trivial" functions (non-trivial meaning that it does more than just print a line of text). My problem is that the text book I am using isn't very helpful so any help would be much appreciated. Thanks
1
1420
by: tracy Anne | last post by:
i am passing a float and a integer into the function error: function does not take 1 arguments #include <stdio.h> #include <stdlib.h> #include <string.h> #define AgentSize 5 void DisplayWelcome(void);
0
9535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10465
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10242
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10021
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9061
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4127
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3744
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2931
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.