473,324 Members | 2,179 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,324 software developers and data experts.

how to tweak the code into modular programming?

Hey guys,i am very very new to c programming and i really need your guys help,please.Below is the code that i use array to collect 5 integer and determine the minimum integer from the 5 integer using c language.

#include<stdio.h>
int main()
{
int i,min;
int number [5];
for(i=0;i<5;i++)
{
printf("enter number:");
scanf("%d",&number[i]);

}
for(i=0;i<5;i++)
{
if(number[i]<min)
{
min=number[i];
}
}
printf("the minimum value is %d",min);
}

AND HERE'S THE QUESTION
use functions to(c language) :
i.Get the 5 integers from user (Function : user_input)
ii.Find the smallest number (Function: find_smallest)
iii.Display the smallest number (Function: Main)

i kinda don't know how to start.
Apr 23 '17 #1
3 1270
weaknessforcats
9,208 Expert Mod 8TB
You kind of coded it already:

Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     user_input();
  4.     find_smallest();
  5.     printresult();
  6. }
  7.  
Step 1 would be to code these functions as empty functions and compile and run the program.

Step 2 would be to fill in the functions. Here you can decide to provide function arguments or have functions return values, like find_smallest() might return the smallest value which could then be passed to printresult() for display. Here is when you can use the code you have to go inside these functions. It's not going to be a perfect fit. You may need to do a little tailoring.

I would start by using global variables to avoid passing function arguments. After the program works, I would remove the global variables and replace them with local variables in main(). Use global variables only in development, never in a finished program.

BTW: In a modular system, main() cannot display the result. There is no way main() can know the display format. You need a function for that.

BTW2: In modular programming each function can do only one thing. If a function has to do two things then it calls two functions each of does only one thing.

Post again as you go along. I'm curious how you will do.
Apr 23 '17 #2
thanks and heres what i have done,but at the place i make it bold,the code said it is redeclared as different symbol and i kinda don't know why,cause i put it integer all the way

#include<stdio.h>
int find_min(int);

int main()
{
int i,min;
int number [5];
int find_min;
for(i=0;i<5;i++)
{
printf("enter number:");
scanf("%d",&number[i]);
find_min=number[i];
printf("the minimum number is %d",min);
return 0;
}

int find_min(int number[i],int i)
{
int min;
for(i=0;i<5;i++)
{
if(number[i]<min)
{
min=number[i];
}
return find_min;
}

}
Apr 24 '17 #3
weaknessforcats
9,208 Expert Mod 8TB
Your function prototype says find_min has one argument, an int.

Inside main() there is another find_min declared as an int variable.

The function in bold says find_min is a function with two arguments, an int and an int.

By the time the compiler got to your function definition it was confused, hence the error.

In any case, a compiler error at a line number means that when the compiler got there, there was an error. The location of the error is that line or any other line preceding up to the beginning f the code.

You should have only one find_min. All symbols must be unique.
Apr 24 '17 #4

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

Similar topics

12
by: Steven T. Hatton | last post by:
This is something I've been looking at because it is central to a currently broken part of the KDevelop new application wizard. I'm not complaining about it being broken, It's a CVS images. ...
37
by: Alan Silver | last post by:
Hello, Newbie here, so please forgive what is probably a basic question ... I see a lot of discussion about "code behind", which if I have understood correctly, means that the script code goes...
26
by: I_AM_DON_AND_YOU? | last post by:
This is the scenario: I have a VB.Net project comprising of a few Forms. On Form1 I have more than 20 buttons. There is a very lenghty code written in click event of each and every button. Right...
3
by: gonzosez | last post by:
Here is what I am talking about... I have an app that extracts data from a customer database and imports it to database2 The 2nd app extracts data from database2 and imports to database3 The...
3
by: DG | last post by:
Please correct me if i'm using a wrong term. I want to programm functionality and pack it to .dll Then, have an application look in 'modules' folder and depending on available .dll-s display...
1
by: bob | last post by:
I have made a file: box.h that have some structs, simple functions etc. I have then made another file: print.h that have a class 'print' with methods to print the content from 'box' (content of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.