- // 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 1806
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 prepares the DB for deployment. It does a
few other things, re-links tables, tuns of shift key bypass etc.
But can I modify the code? do I need to use #if ?
thanks
|
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 USPS. I
need sample code for unpack XML response for USPS tracking. Sample
code should be in PHP language. If it is not available in PHP, other
language like PERL, JAVA etc is acceptable.
Thanks and regards
Riyadh Hossain
| |
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 or send it.
|
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 user will input his number,
then he will choose also what operation to use..
|
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 numbers.
Now i use this script for validate the email address. But it allows the cpital letters otherwise its working correctly.
SCRIPT FUNCTION
************************************************
|
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...
|
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...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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
| |
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...
| |