- // function prototypes
-
void inputdata();
-
void printdata();
-
-
// Global variables
-
// These are available to all functions
-
float Raindata[NUMYEARS][NUMMONTHS];
-
char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
-
char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
-
int main ()
-
{
-
char enterData = 'y';
-
printf("Do you want to input Precipatation data? (y for yes)\n");
-
scanf("%c",&enterData);
-
if (enterData == 'y') {
-
// Call Function to Input data
-
inputdata();
-
-
// Call Function to display data
-
printdata();
-
}
-
else {
-
printf("No data was input at this time\n");
-
}
-
printf("Please try the Precipitation program again. \n");
-
return 0;
-
}
-
// function to inputdata
-
void inputdata() {
-
/* variable definition: */
-
float Rain=1.0;
-
// Input Data
-
for (int year=0;year < NUMYEARS; year++) {
-
for (int month=0; month< NUMMONTHS; month++) {
-
printf("Enter rain for %d, %d:\n", year+1, month+1);
-
scanf("%f",&Rain);
-
Raindata[year][month]=Rain;
-
}
-
}
-
}
-
// Function to printdata
-
void printdata(){
-
// Print data
-
printf ("year\t month\t rain\n");
-
for (int year=0;year < NUMYEARS; year++) {
-
for (int month=0; month< NUMMONTHS; month++) {
-
printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
-
}
-
}
-
}
-
-
This is what I've started need help to finish it - // Function to sum toatal rainfall per year
-
void printdata(){
-
// Print data
-
printf ("rain+month\n");
-
for (int month=0; month< NUMMMONTHS; month++) {
-
-
}
-
}
-
8 1796
Have you considered using a struct for Raindata? - struct Raindata
-
{
-
int year;
-
int RainByMonth[12];
-
}
This would simplify your code. To get the yearly rain amount you would just add the elements of the RainByMonth array.
What do you think?
where would I place this?
You were going to use global variables to avoid passing arguments to functions. While this is not a good idea, it does work. So you could: -
struct Raindata
-
{
-
-
-
int year;
-
-
int RainByMonth{12];
-
-
};
-
-
-
-
-
Raindata RainByYears[10];
-
-
-
int main()
-
{
-
-
}
Every function can now access the RainByYears array. I just made up the 10.
would you mind showing me where to place it in my code please and thank you
The compiler has got know your types and your functions before you use them in the code.
All those #include are to provide this information.
You would place the struct definition above main() but after the #includes.
You would place the Raindata array after the struct definition but before main().
Look at my last post.
- #define NUMMONTHS 12
-
#define NUMYEARS 5
-
#include <stdio.h>
-
-
// function prototypes
-
void inputdata();
-
void printdata();
-
-
// Global variables
-
// These are available to all functions
-
float Raindata[NUMYEARS][NUMMONTHS];
-
char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
-
char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
-
int main ()
-
{
-
char enterData = 'y';
-
printf("Do you want to input Precipatation data? (y for yes)\n");
-
scanf("%c",&enterData);
-
if (enterData == 'y') {
-
// Call Function to Input data
-
inputdata();
-
-
// Call Function to display data
-
printdata();
-
}
-
else {
-
printf("No data was input at this time\n");
-
}
-
printf("Please try the Precipitation program again. \n");
-
return 0;
-
}
-
// function to inputdata
-
void inputdata() {
-
/* variable definition: */
-
float Rain=1.0;
-
// Input Data
-
for (int year=0;year < NUMYEARS; year++) {
-
for (int month=0; month< NUMMONTHS; month++) {
-
printf("Enter rain for %d, %d:\n", year+1, month+1);
-
scanf("%f",&Rain);
-
Raindata[year][month]=Rain;
-
}
-
}
-
}
-
// Function to printdata
-
void printdata(){
-
// Print data
-
printf ("year\t month\t rain\n");
-
for (int year=0;year < NUMYEARS; year++) {
-
for (int month=0; month< NUMMONTHS; month++) {
-
printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
-
}
-
}
-
}
-
-
So where would I place the sum of rainfall per year
- #define NUMMONTHS 12
-
#define NUMYEARS 5
-
#include <stdio.h>
-
-
// function prototypes
-
void inputdata();
-
void printdata();
-
-
// Global variables
-
// These are available to all functions
-
float Raindata[NUMYEARS][NUMMONTHS];
-
char years[NUMYEARS][5] = {"2011","2012","2013","2014","2015"};
-
char months[NUMMONTHS][12] ={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
-
int Raindata;
-
int Years;
-
int sum = Raindata + Years;
-
int main ()
-
{
-
char enterData = 'y';
-
printf("Do you want to input Precipatation data? (y for yes)\n");
-
scanf("%c",&enterData);
-
if (enterData == 'y') {
-
// Call Function to Input data
-
inputdata();
-
-
// Call Function to display data
-
printdata();
-
}
-
else {
-
printf("No data was input at this time\n");
-
}
-
printf("Please try the Precipitation program again. \n");
-
return 0;
-
}
-
// function to inputdata
-
void inputdata() {
-
/* variable definition: */
-
float Rain=1.0;
-
// Input Data
-
for (int year=0;year < NUMYEARS; year++) {
-
for (int month=0; month< NUMMONTHS; month++) {
-
printf("Enter rain for %d, %d:\n", year+1, month+1);
-
scanf("%f",&Rain);
-
Raindata[year][month]=Rain;
-
}
-
}
-
}
-
// Function to printdata
-
void printdata(){
-
// Print data
-
printf ("year\t month\t rain\n");
-
for (int year=0;year < NUMYEARS; year++) {
-
for (int month=0; month< NUMMONTHS; month++) {
-
printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
-
}
-
}
-
//Function to sum rainfall
-
sum = rain + year;
-
printf("rainfall per year");
-
}
I'm getting a bunch of errors
prog.c:14:6: error: conflicting types for ‘Raindata’
int Raindata;
^~~~~~~~
prog.c:11:7: note: previous declaration of ‘Raindata’ was here
float Raindata[NUMYEARS][NUMMONTHS];
^~~~~~~~
prog.c:16:12: error: initializer element is not constant
int sum = Raindata + Years;
^~~~~~~~
prog.c: In function ‘inputdata’:
prog.c:44:19: error: subscripted value is neither array nor pointer nor vector
Raindata[year][month]=Rain;
^
prog.c: In function ‘printdata’:
prog.c:54:73: error: subscripted value is neither array nor pointer nor vector
printf("%s\t %s\t %5.2f\n", years[year],months[month],Raindata[year][month]);
^
prog.c:58:8: error: ‘rain’ undeclared (first use in this function)
sum = rain + year;
^~~~
prog.c:58:8: note: each undeclared identifier is reported only once for each function it appears in
prog.c:58:15: error: ‘year’ undeclared (first use in this function)
sum = rain + year;
The rule is that you fix only the first error. Often,the first error also causes other errors that will go away when the first error is fixed.
In this case, the first error is caused by having two Raindata variables. One is an array of float and the other is an int.
Fix that, recompile, and repeat fixing first errors until your errors go away.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Cibulya Dmitriy |
last post by:
Hi All,
I want to catch the next MSSQL error in my SQL code with following continue
calculations
Server: Msg 17, Level 16, State 1, Line 1
SQL Server does not exist or access denied.
|
by: Baldy |
last post by:
Hi All
is it possible to modify code at run time? I have a set of constants that
change at deployment (from development to deployment server and a few other
consts) I have a menu item that...
|
by: Mark Kamoski |
last post by:
Hi--
Please help.
I need a code sample for bubble sort.
Thank you.
--Mark
|
by: Mark Kamoski |
last post by:
Hi Everyone--
Please help.
I need a code sample for merge sort.
Thank you.
--Mark
|
by: Riyadh Hossain |
last post by:
I am developing USPS shipping API for my site. All the work is going on
testing phase. My site uses PHP/MySQL. Now I am working on USPS
tracking/confirm. I can send request and get responses from...
|
by: ravibrl |
last post by:
Hey I need c++ code to access a webpage and download some software. If I execute that it should download that software and it should install it in my system. Give suggestions how to write that code...
|
by: Krishna |
last post by:
In vb2005 I can't modify code in debug mode why? Is it possible to set?
Thanks
|
by: dee vee bee |
last post by:
this is my project
i need a code that will show like this..
"first number __"
"second number ___"
"choose operation:
addition..subtraction..multiplication..division"
"the answer is ___"
the...
|
by: saravanatmm |
last post by:
I need javascript code for validate the email address.
Email address field cannot allowed the capital letters, special characters except '@' symbol.
But can allowed the small letters, numeric...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
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...
|
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...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
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,...
|
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...
|
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...
|
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...
| |