| | |
arrays! a little help!
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
oopss i still have a problem!!.. What's wrong with my code?
now my aim is to add all the values of first month and then print it. and same as the second month.(add all the values of second month and then print it). And when i run the program and then i put a values in the first month and its working fine but my problem is in second month because after i put a values in second month, the output of 1st month will add to the values of second month.
ex.
JANUARY
Numbers of Rainfall:4
Numbers of Rainfall:3
Numbers of Rainfall:2
Numbers of Rainfall:1
The numbers of rainfall in the first month 10
FEBRUARY
Numbers of Rainfall:5
Numbers of Rainfall:4
Numbers of Rainfall:3
Numbers of Rainfall:2
The numbers of Rainfall in Second month 24
now i need help on the second month on how to print the second month without adding the first month..?
Sorry i'm a newbie programmer but i'm studying hard. thanks guys..
C++ Syntax (Toggle Plain Text)
main() { int a[4]; int b[4]; int counter,sum=0; cout<<"JANUARY"; for(counter=0;counter<4;counter++) { cout<<"Numbers of Rainfall:"; cin>>a[counter]; } for(counter=0;counter<4;counter++) { sum+=a[counter]; } cout<<"The numbers of rainfall in the first month"<<sum<<endl; cout<<FEBRUARY; for(counter=0;counter<4;counter++) { cout<<"Numbers of Rainfall"; cin>>b[counter]; } for(counter=0;counter<4;counter++) { sum+=b[counter]; } cout<<"The numbers of rainfall in the second month"<<sum<<endl; getch(); return 0; }
ex.
JANUARY
Numbers of Rainfall:4
Numbers of Rainfall:3
Numbers of Rainfall:2
Numbers of Rainfall:1
The numbers of rainfall in the first month 10
FEBRUARY
Numbers of Rainfall:5
Numbers of Rainfall:4
Numbers of Rainfall:3
Numbers of Rainfall:2
The numbers of Rainfall in Second month 24
now i need help on the second month on how to print the second month without adding the first month..?
Sorry i'm a newbie programmer but i'm studying hard. thanks guys..
Last edited by Narue; Dec 5th, 2008 at 11:18 am. Reason: added code tags
"One more round and it's bottle to the ground"
-NOFX
-NOFX
•
•
Join Date: Jun 2008
Posts: 182
Reputation:
Solved Threads: 18
Just put
Please read this and make sure to use code tags when posting code from now on
EDIT: sweeya was faster, sorry.
sum = 0; before starting to add the second month rainfalls.Please read this and make sure to use code tags when posting code from now on
EDIT: sweeya was faster, sorry.
Last edited by mrboolf; Dec 5th, 2008 at 11:21 am.
Well as they already said reset sum to zero; next problem in month two would be, you forgot quotes
You could create a class that holds all of the months, extra info and functions that deal with them; if you've gotten that far in your studies, yet.
" in cout, and I'm assuming the lack of int before main() is a copy-paste oversight.You could create a class that holds all of the months, extra info and functions that deal with them; if you've gotten that far in your studies, yet.
"Jedenfalls bin ich überzeugt, daß der Alte nicht würfelt."
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
"I became very sensitive to what will happen to all this and all of us." -Two geniuses named Albert
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: i want an instant answer
- Next Thread: How to Initialize COM Library in VC++.NET 2005
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





