It's my assignment I have done almost I have completed it.But I have problem in getting input from user(the bank name)here is my assignment question.
Customer often wait in the bank..!you have to ask the user the entire as many bank names as he desires and time (waiting time the user waited)
in the following format.
HSBC BANK | 6.4 6.6 7.5 2.2 3.4 5.6 |
Lloyds bank | 5.3 2.3 3.4 5.3 3.4|

the program should calculte the standard deviation and mean.
and the one with least standard deviation should be informed to the user!
The calculation part works perfectly fine,I don't know how to make it in that format!if I use cin.getline it goes to next line after the user inputs the name,so it will change the required format!please help me in getting it in that format!THANKS

void Mean(double arr[],double size,double &counter,double &mean,double &declared,double sum);
void standardDeviation(double deviation,double &mean,double &counter,double variance,double power,double now,double temp,double arr[],double &declared);
using namespace std;
int main()
    double sum = 0,mean = 0,counter = 0,size = 100,declared = 0 ,variance = 0,now =0,temp =0,power=0,deviation = 0;
	double arr[1000];
    cout<<"enter size"<<endl;
    cout<<"enter input"<<endl;

standardDeviation(deviation,mean, counter, variance, power, now, temp, arr,declared);
void Mean(double arr[],double size,double &counter,double &mean,double &declared,double sum)
   for(int i=0;i<declared;i++)
           // cout<<"counter is: "<<counter;
   //cout<<"sum is : "<<sum<<endl;
     cout<<"mean is: "<<mean<<endl;


void standardDeviation(double deviation,double &mean,double &declared,double variance,double power,double now,double temp,double arr[],double &counter)

 for(int i =0; i<counter;i++)
now= arr[i]-mean;
		//cout<<"value: "<<i+1<<"is: "<<now<<"  ";
		//cout<<"power of: "<<i+1<<"is: "<<power<<endl;
	//cout<<"sum of powers are: "<<temp<<endl;
//cout<<"Standard Variance"<<variance<<endl;
cout<<"Standard Deviation is: "<<deviation;


Recommended Answers

All 5 Replies

You should simplify the problem. This problem has nothing to do with a bank, so why mention a bank? Ask something like

I want to input a line like
"MyName 2.3 4.5 6.7"
and store the input in a string and 3 doubles. How do I do that?


I know how to use strings

using namespace std;
int main()
string name;
double x,y,z;
cout<<"enter name"<<endl;
cout<<" ";
return 0;

but the problem is If I don't know how many time's the user is going to enter data then how could I use strings for names!
plus the input should be this format
name | 12.2 23.3 343.2 |
secondname | 12.23 34.4 34.4 |
name is the bank name which the user will enter

You should simplify the problem. This problem has nothing to do with a bank, so why mention a bank? Ask something like


>>I know how to use strings.
To use STL strings you need to include the header file called string.

To read a string that has whitespace in it, such as the following:

name | 12.2 23.3 343.2 |

you need to use getline(), not >>; as >> stops input into the current variable when it encounters whitespace.

Sooner or later you are going to have to break that line of input up into it's component parts. That's where the advise to look up stringstreams comes in. For example you could use getline() the pipe char as the delimiting char to split the input up into a name string and a data string. You could then use a stringstream to break up the data string into individual numerical data pieces.

As I said in your other thread on this topic, if you don't know the number of lines of input or the number of data points per line, you need a container to hold them if you plan to reuse the information at a later point in the program. If you know an upper limit as to the number of inputs you can use arrays to hold them; just be sure the arrays are large enough to hold everything so you don't overwrite your memory. The alternative is to use a self expanding container so you don't have to worry so much about overwriting memory. Vectors are one container that can do that, but lists and other containers could also be used.

Use the Loops and ask user to enter input. After finishing ask Him something like "Finished" with Y/N? options if Y break the loop and if no Continue. Now I hope you know which loop im talking about :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.