| | |
Arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2007
Posts: 11
Reputation:
Solved Threads: 0
The program of the output shows everything correctly. Just have one more question. How can I show for each column heading display of its appropriate value.
For example:
Current Resistance Volts
This is my program:
For example:
Current Resistance Volts
This is my program:
c++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int main() { // This for loop enters the current values. const int ARRAYSIZE = 10; int i, current[ARRAYSIZE]; for (i = 0; i < ARRAYSIZE; i++) // Enter the current values { cout << "Enter a number: "; cin >> current[i]; } // This for loop enters the resistance values. const int SIZE = 10; int j, resistance[SIZE]; for (j = 0; j < SIZE; j++) // Enter the resistance values { cout << "Enter a number: "; cin >> resistance[j]; } // This for loop calculates and displays the voltage. const int MAXNUMS = 10; int k, volts[MAXNUMS]; for (k = 0; k < MAXNUMS; k++) { volts[k] = current[k] * resistance[k]; cout << current[k] << '\t' << resistance[k] << '\t' << volts[k] << endl; } return 0; }
Last edited by Ancient Dragon; Nov 24th, 2007 at 7:36 pm. Reason: add code tags -- 4th attempt
•
•
Join Date: Nov 2007
Posts: 11
Reputation:
Solved Threads: 0
Thank You. The other program worked fine.
Now for the last program, the program states to store the following prices in an array named resistance: 16, 27, 39, 56, and 81. Your program should also create two arrays named current and power each capable of storing five double precision numbers. Using a for loop and a cin statement have your program accept 5 user input values into the current array once the program is run. Your program should store the product of the corresponding values of the square of the current array and the resistance array in the power array (for example, power[1] = resistance[1] * pow(current[1],2) and displays the following output.
I have done the program. I just want some feedback if I have done the program the right way.
Thanks.
Now for the last program, the program states to store the following prices in an array named resistance: 16, 27, 39, 56, and 81. Your program should also create two arrays named current and power each capable of storing five double precision numbers. Using a for loop and a cin statement have your program accept 5 user input values into the current array once the program is run. Your program should store the product of the corresponding values of the square of the current array and the resistance array in the power array (for example, power[1] = resistance[1] * pow(current[1],2) and displays the following output.
I have done the program. I just want some feedback if I have done the program the right way.
Thanks.
c++ Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> using namespace std; int main() { const int MAXELS = 5; int i, num, resistance[MAXELS] = {16, 27, 39, 56, 81}; num = resistance[0]; // This for loop contains the cin statement to accept five user input numbers for the current. const int MAXNUMS = 5; int j, current[MAXNUMS]; for (j = 0; j < MAXNUMS; j++) { cout << " " << current[j]; cin >> current[j]; } // This for loop that calculates the power and the total then it displays the result. const int ARRAYSIZE = 5; int k, power[ARRAYSIZE]; for (k = 0; k < MAXNUMS; k++) { power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); cout << power[k] << endl; } return 0; }
Last edited by Ancient Dragon; Nov 25th, 2007 at 9:48 am. Reason: add code tags
Are you dumber than a box of rocks?
Do none of these comments mean anything to you?
Last edited by Ancient Dragon : 1 Day Ago at 03:19. Reason: add code tags
Last edited by Ancient Dragon : 1 Day Ago at 04:53. Reason: add code tags
Last edited by Ancient Dragon : 1 Day Ago at 04:55. Reason: This is the third time I've had to add code tags
Last edited by Ancient Dragon : 8 Hours Ago at 23:36. Reason: add code tags -- 4th attempt
Are you not even the tiniest bit curious as to why your posts change to be nicely formatted?
Did you even bother to read this thread?
http://www.daniweb.com/forums/announcement8-3.html
Do you even notice the water mark at the back of the edit window telling you about code tags?
Have you ever considered using the "preview post" feature to make sure you're presenting your question in the best possible light?
Do none of these comments mean anything to you?
Last edited by Ancient Dragon : 1 Day Ago at 03:19. Reason: add code tags
Last edited by Ancient Dragon : 1 Day Ago at 04:53. Reason: add code tags
Last edited by Ancient Dragon : 1 Day Ago at 04:55. Reason: This is the third time I've had to add code tags
Last edited by Ancient Dragon : 8 Hours Ago at 23:36. Reason: add code tags -- 4th attempt
Are you not even the tiniest bit curious as to why your posts change to be nicely formatted?
Did you even bother to read this thread?
http://www.daniweb.com/forums/announcement8-3.html
Do you even notice the water mark at the back of the edit window telling you about code tags?
Have you ever considered using the "preview post" feature to make sure you're presenting your question in the best possible light?
•
•
Join Date: Nov 2007
Posts: 11
Reputation:
Solved Threads: 0
Sorry if I didn't get the code tags. I'm a new user and trying to be in the environment here.
Thank You for the other program it worked just fine.
Now for the last program, the program states to store the following prices in an array named resistance: 16, 27, 39, 56, and 81. Your program should also create two arrays named current and power each capable of storing five double precision numbers. Using a for loop and a cin statement have your program accept 5 user input values into the current array once the program is run. Your program should store the product of the corresponding values of the square of the current array and the resistance array in the power array (for example, power[1] = resistance[1] * pow(current[1],2) and displays the following output.
This is my program:
Thank You for the other program it worked just fine.
Now for the last program, the program states to store the following prices in an array named resistance: 16, 27, 39, 56, and 81. Your program should also create two arrays named current and power each capable of storing five double precision numbers. Using a for loop and a cin statement have your program accept 5 user input values into the current array once the program is run. Your program should store the product of the corresponding values of the square of the current array and the resistance array in the power array (for example, power[1] = resistance[1] * pow(current[1],2) and displays the following output.
This is my program:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <cmath> using namespace std; int main() { const int MAXELS = 5; int i, num, resistance[MAXELS] = {16, 27, 39, 56, 81}; num = resistance[0]; // This for loop contains the cin statement to accept five user input numbers for the current. const int MAXNUMS = 5; int j, current[MAXNUMS]; for (j = 0; j < MAXNUMS; j++) { cout << " " << current[j]; cin >> current[j]; } // This for loop that calculates the power and the total then it displays the result. const int ARRAYSIZE = 5; int k, power[ARRAYSIZE]; for (k = 0; k < MAXNUMS; k++) { power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); power[k] = resistance[k] * pow(current[k],2); cout << power[k] << endl; } return 0; }
![]() |
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: need help writing function
- Next Thread: Microsoft Visual C++ Express
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






