GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #11  
Old 28-Oct-2009, 23:26
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: How do I add arrays into my program?!?!


Well the output I get is:
Code:
Please input 's' for series OR 'p' for resistors parallel s Please enter the number of resistors connected 3 Input value of series resistor number 1 2.34 Input value of series resistor number 2 4.6 Input value of series resistor number 3 2.5 Resistor: 6 Resistor: 6 Resistor: 6 Resistor: 6 Resistor: 6 Resistor: 6 The total resistance is less than 1000 and its value is 9.44 Ohm
...and you would like to see something like (from above):
Code:
For series: (Example) Total series resistance is 2.123 kOhm for 3 resistors: 1000 kOhm, 1000 kOhm, 123 kOhm For parallel: (Example) Total series resistance is 500 Ohm for 2 resistors: 1000 Ohm, 1000 Ohm
Well , for one thing you have this loop:
CPP / C++ / C Code:
    int array [] = {1,2,3,4,5,6};
    int length = sizeof(array) / sizeof(int);
    for(int i = 0; i < length; i++)
    {
      cout << "Resistor: " << length << endl;
    }
...before the "Total resistance ..." line.
For another you print the array "length" and an endl; what did you expect to see?
Why aren't you using the array r[] and iterating the "number_of_resistors_connected" times?
...as far as the endl; goes you should dump that and print something like " Ohm, " or somesuch to go between each value.
Last edited by Howard_L : 29-Oct-2009 at 00:47.
  #12  
Old 29-Oct-2009, 00:28
sl02ggp sl02ggp is offline
New Member
 
Join Date: Oct 2009
Posts: 25
sl02ggp is on a distinguished road

Re: How do I add arrays into my program?!?!


thanks! should be r[i]....and what do you mean by "," instead of endl?

also most of the time when setting up an array
the values are listed like this:
121
3434

how do i get it like this: 121, 3434

and how do i make my program realize i have input "blank" number of resistors for when it says

Total series resistance is 2.123 kOhm for "3" resistors:
1000 kOhm, 1000 kOhm, 123 kOhm
  #13  
Old 29-Oct-2009, 01:14
Howard_L Howard_L is offline
Regular Member
 
Join Date: Apr 2007
Location: Maryland/PA, USA
Posts: 802
Howard_L is a jewel in the roughHoward_L is a jewel in the roughHoward_L is a jewel in the rough

Re: How do I add arrays into my program?!?!


I think this will give you some ideas to start with.
Add stuff to customize to your liking and then incorporate it into your program:
CPP / C++ / C Code:
#include <iostream>  /* printing arrays 101 */
using namespace std;

int main()
{
  int i, number_of_resistors_connected = 4;
  double r[5] = {1.5, 2.3, 4.5, 6.4, 0 };

  for ( i = 0; i < number_of_resistors_connected; i++)
  {
    cout << r[i] << " Ohm";
    if (i < number_of_resistors_connected - 1)
    {
      cout << ", ";
    }
  }
  cout << endl;
  return 0;
}
  #14  
Old 29-Oct-2009, 10:29
zalezog zalezog is offline
Junior Member
 
Join Date: Oct 2007
Posts: 33
zalezog will become famous soon enough

Re: How do I add arrays into my program?


The program still wouldn't work the way you want it to.
THe formula for parallel resiatance should be:
CPP / C++ / C Code:
if (type == 'p') {
           total_resistance = 0.0;
            for (int i = 0; i < number_of_resistors_connected; i++) {
                cout << "Input value of  parallel resistor number " << i + 1 << endl;
                cin >> r[i];
                if (!cin || r[i] == 0) {
                    cout << "Invalid input." << endl;

                }
                total_resistance += 1 / r[i];
            }
        }
	}
The while loop should have a particular condition to continue.
CPP / C++ / C Code:
    char yes_no = 'y';
    while (yes_no == 'y' || yes_no == 'Y') {
    .
    .
    .
         // get user input whether to continue or not
        //Also delete the memory allocated :delete[]r
       //If you are using character input along with integer input
      //flush the buffer before beginning the next iteration.
       
    }
 
 

Recent GIDBlogProgramming ebook direct download available by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Equation solver RazoR C Programming Language 3 18-May-2008 10:24
Need Help with input files. Efferus C++ Forum 2 24-Nov-2007 17:19
Two-Tier data dissemination code installation problem nidhibansal1984 Computer Software Forum - Linux 6 16-Sep-2007 11:13
program without arrays dezstylz C++ Forum 3 31-May-2006 09:24

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 14:53.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.