Why can't my coding get anything from the file? C++ - text

There is no error for this coding.It just can't get any output when we try to get data from the file.I use JGrasp for the compiler. I think there is something wrong in the getfile part.But I identify every line and can't seem to find any.
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int customer = 20;
void menuOption (); //define function
void applicationInfo (string custName [], int ic [] ,float salary [] ,int no_loan [] ,float loanPayment [] );
void requirement (string custName [], int ic [] ,float salary [],int no_loan [],float LoanAmount [],float loanPayment [],char typeOfCard [],int detail );
void Platinum (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment []);
void Gold (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment []);
void Silver (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment []);
void nonEligible (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment []);
void exitPrg ();
void wrongOption ();
void main()
{
int menu, ic [customer], no_loan [customer], detail;
float salary [customer], loanPayment [customer], LoanAmount [customer];
char typeOfCard [customer];
string custName [customer];
menuOption ();
cin >> menu;
switch (menu)
{
case 1:
applicationInfo (custName ,ic ,salary , no_loan ,loanPayment );
requirement ( custName , ic, salary, no_loan, LoanAmount, loanPayment, typeOfCard, detail );
break;
case 2:
Platinum ( ic , typeOfCard , custName , salary , no_loan , loanPayment );
break;
case 3:
Gold (ic ,typeOfCard , custName , salary , no_loan , loanPayment );
break;
case 4:
Silver (ic ,typeOfCard , custName , salary ,no_loan , loanPayment );
break;
case 5:
nonEligible (ic , typeOfCard , custName ,salary , no_loan , loanPayment );
break;
case 6:
exitPrg ();
break;
default:
wrongOption ();
}
} //End of void main
void menuOption ()
{
cout << " One Stop Financing Company " << endl; //Menu option for user to choose.
cout << "\n 1. Application from customers " << endl;
cout << " 2. Display of PLATINUM card holder " << endl;
cout << " 3. Display of GOLD card holder " << endl;
cout << " 4. Display of SILVER card holder " << endl;
cout << " 5. Display non eligible application " << endl;
cout << " 6. EXIT " << endl;
cout << "\n Please enter your choice " << endl;
} //End of void menuOption
void applicationInfo (string custName [], int ic [], float salary [], int no_loan [], float loanPayment [] )
{
ifstream infile ("listofloaners");
int i = 0;
while ( !infile.eof () )
{
getline ( infile, custName [i] );
infile >> ic [i];
infile >> salary [i];
infile >> no_loan [i];
infile >> loanPayment [i];
i++;
}
}
void requirement (string custName [], int ic [], float salary [], int no_loan [], float LoanAmount [], float loanPayment [], char typeOfCard [], int detail )
{
const float minSalary = 3000;
const int financingLoan = 1;
for (int j = 0; j < customer; j++)
{
if (salary [j] >= minSalary)
{
if (no_loan [j] == financingLoan)
{
LoanAmount[j] = 0.25 * salary [j];
if (LoanAmount [j] < loanPayment [j])
{
if (salary [j] >= 20000)
typeOfCard [j] = 'P';
else if (salary [j] >= 10000)
typeOfCard [j] = 'G';
else
typeOfCard [j] = 'S';
}
else
{
cout << "Sorry you are not eligible for this application. If you want to know the details please tap 5." << endl;
cin >> detail;
while (detail != '5')
{
cout << "Please enter right number. If you want to know the details please tap 5." << endl;
cin >> detail;
}
nonEligible (ic , typeOfCard , custName ,salary , no_loan , loanPayment );
}
}
else
{
cout << "Sorry you are not eligible for this application. If you want to know the details please tap 5." << endl;
cin >> detail;
while (detail != '5')
{
cout << "Please enter right number. If you want to know the details please tap 5." << endl;
cin >> detail;
}
nonEligible (ic , typeOfCard , custName ,salary , no_loan , loanPayment );
}
}
else
{
cout << "Sorry you are not eligible for this application. If you want to know the details please tap 5." << endl;
cin >> detail;
while (detail != '5')
{
cout << "Please enter right number. If you want to know the details please tap 5." << endl;
cin >> detail;
}
nonEligible (ic , typeOfCard , custName ,salary , no_loan , loanPayment );
}
}
} //End of void requirement
void Platinum (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment [])
{
for (int a = 0; a < customer; a++)
{
if ( typeOfCard [a] == 'P' )
{
cout << " INFORMATION OF PLATINUM CARD HOLDER " << endl << endl;
cout << "Name : " << custName [a] << endl;
cout << "IC No. : " << ic [a] << endl;
cout << "Monthly Salary : " << salary [a] << endl;
cout << "Monthly Loan Payment : " << loanPayment [a] << endl;
cout << "Total Loan : " << no_loan [a] << endl;
cout << "Type of Card : Platinum " << endl;
cout << "Credit Limit : RM 50 000 " << endl;
}
}
} //End of void Platinum
void Gold (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment [])
{
for (int b = 0; b < customer; b++)
{
if ( typeOfCard [b] == 'G' )
{
cout << " INFORMATION OF GOLD CARD HOLDER " << endl << endl;
cout << "Name : " << custName [b] << endl;
cout << "IC No. : " << ic [b] << endl;
cout << "Monthly Salary : " << salary [b] << endl;
cout << "Monthly Loan Payment : " << loanPayment [b] << endl;
cout << "Total Loan : " << no_loan [b] << endl;
cout << "Type of Card : Gold " << endl;
cout << "Credit Limit : RM 15 000 " << endl;
}
}
}
void Silver (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment [])
{
for (int c = 0; c < customer; c++)
{
if ( typeOfCard [c] == 'S' )
{
cout << " INFORMATION OF SILVER CARD HOLDER " << endl << endl;
cout << "Name : " << custName [c] << endl;
cout << "IC No. : " << ic [c] << endl;
cout << "Monthly Salary : " << salary [c] << endl;
cout << "Monthly Loan Payment : " << loanPayment [c] << endl;
cout << "Total Loan : " << no_loan [c] << endl;
cout << "Type of Card : Silver " << endl;
cout << "Credit Limit : RM 5 000 " << endl;
}
}
} //End of void Silver
void nonEligible (int ic [],char typeOfCard [],string custName [],float salary [],int no_loan [],float loanPayment [])
{
for (int d = 0; d < customer; d++)
{
if (typeOfCard [d] != 'P' || typeOfCard [d] != 'G' || typeOfCard [d] != 'S')
{
cout << " INFORMATION OF NON ELIGIBLE APPLICATION " << endl << endl;
cout << "Name : " << custName [d] << endl;
cout << "IC No. : " << ic [d] << endl;
cout << "Monthly Salary : " << salary [d] << endl;
cout << "Monthly Loan Payment : " << loanPayment [d] << endl;
cout << "Financing Loan : " << no_loan [d] << endl;
cout << "Reason : Because you are not fulfil the application criteria." << endl;
cout << "**Either your monthly salary or financing loan more than 1 or loan amount must less than 25%. " << endl;
}
}
} //End of void nonEligible
void exitPrg ()
{
cout << "\nThank you. Your session has expired. " << endl;
} //End of void exitPrg
void wrongOption ()
{
cout << "\nYou enter wrong option. Please try again to continue. " << endl;
} //End of void wrongOption
this is my file that i'm trying to get.
Ahmad Albab
030211020712 12000 1 30000 June Press
030201020567 36000 2 40000 Jane Mary
348478476378 10000 5 10000
I tried different coding for the part of getting the file.Still can't get it done.

Related

Numerical Integration with Unspecified Parameter in C++

I have written a simple code to calculate an integral numerically with both the midpoint and trapezoidal rule. It works fine, but now I would like to modify it so that it can calculate the same integral but with an unspecified parameter. So instead of the integral of e^(-x^2), I would like to calculate the integral of e^(-\alpha*x^2). However, I am stuck here. I tried to just declare a new double alpha without initializing it, but that clearly takes me no where. Is there a way to do such a thing in C++? Thank you in advance.
//=============================================================
// A simple program to numerically integrate a Gaussian over
// the interval a to b
//=============================================================
#include <iostream>
#include <cmath>
using namespace std;
// function implementing the midpoint rule
double midpoint(double a, double b, int n){
double sum = 0.0;
double width = (b-a)/n;
for (int i = 1; i < n; i++){
sum += exp((-1)*(a+(i+0.5)*width)*(a+(i+0.5)*width))*width;
}
return sum;
}
//function implementing the trapezoidal rule
double trapezoidal(double a, double b, int n){
double width = (b-a)/n;
double sum = (width/2)*(exp(-a*a)+exp(-b*b));
for (int i = 1; i < n; i++){
sum += 2*exp((-1)*(a+i*width)*(a+i*width))*width/2;
}
return sum;
}
int main(){
cout << "THIS IS A SIMPLE PROGRAM TO INTEGRATE A GAUSSIAN OVER A CERTAIN INTERVAL." << endl;
int n;
double a, b;
cout << "Enter the lower and upper limit of integration as doubles" << endl;
cin >> a >> b;
cout << "Enter the number of partitions" << endl;
cin >> n;
double actual = 0.886207;
double midRule = midpoint(a,b,n);
double trapRule = trapezoidal(a,b,n);
cout << "For the function e^(-x^2) integrated from "<< a << " to " << b << endl;
cout << "The analytic value of the integral is: " << actual << endl;
cout << "The midpoint value of the integral for " << n << " partitions is: " << midRule << endl;
cout << "The trapezoidal value of the integral for " << n << " partitions is: " << trapRule << endl;
cout << "The percent error for the midpoint is: " << (abs(actual-midRule)/actual)*100 << "%" << endl;
cout << "The percent error for the trapezoidal is: " << (abs(actual-trapRule)/actual)*100 << "%" << endl;
return 0;
}

C++ My program is in infinite loop

I appreciate you taking the time to read my problem sorry I'm just a beginner in programming. Apparently I am not that good in loops and if else statement and I don't know whats wrong in my code. when I run it and input "up" its just go to (8,10). it should have been (0,1) then the console will ask which direction they want to go again. Thanks in advance!!! :D
#include<iostream>;
#include<string>;
using namespace std;
int main()
{
int x = 0;
int y = 0;
string input;
cout << "objective: go to (8,9)" << endl;
cout << "current location (" << x << "," << y << ")" << endl;
while ( (x = 8) && (y = 9) )
{
cout << "which way do you want to go?: ";
cin >> input;
if (input == "up")
{
++y;
cout << "current location (" << x << "," << y << ")" << endl;
break;
}
else if (input == "down")
{
--y;
cout << "current location (" << x << "," << y << ")" << endl;
break;
}
else if (input == "right")
{
++x;
cout << "current location (" << x << "," << y << ")" << endl;
break;
}
else if (input == "left")
{
--x;
cout << "current location (" << x << "," << y << ")" << endl;
break;
}
}
cout << "current location (" << x << "," << y << ")" << endl;
cout << "Congratulations! You have reach your destination! :D" << endl;
system("pause");
return(0);
}
"
I tried removing all the break but it went straight down to "congratulations! you have reach your destination" when I tried to run it and I change the condition to (x ==8) && (y ==9) still no improvement.
"
Your loop condition is incorrect. The while loop will only run if x is 8 and y is 9. They are 0 and 0 at the beginning of the program, which explains why we skip the loop. The real condition is: "run the loop as long as x and y are not these values." while (x != 8 || y != 9) and alternately alternately: while (!(x == 8 && y == 9))

Expression must have pointer-to-object type Error?

[Updated Code Pictutre][1]Can someone help me understand what I am doing wrong with my array in this code? It is giving me the same error for all my variables of the array
I dont know how to show you the whole code without adding like 5 pictures, i tried to capture all the important information
Ok I have posted the code here below
#include <iostream>
#include <math.h>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;
int main() {
// output for a single input driving frequency
double m, c1, c2, k1, k2, r, Y;
m = c1 = c2 = k1 = k2 = r = Y = 0;
//input values for the case
cout << "Mass: ";
cin >> m;
cout << "c1: ";
cin >> c1;
cout << "c2: ";
cin >> c2;
cout << "k1: ";
cin >> k1;
cout << "k2: ";
cin >> k2;
cout << "r: ";
cin >> r;
cout << "Y: ";
cin >> Y;
//solve for the equivlent values
double ceq, keq, wn, dampratio, staticamp;
ceq = c1 + c2;
keq = k1 + k2;
wn = 0;
wn = sqrt(keq / m);
dampratio = ceq / (2 * sqrt(m*keq));
//Determine the Case
double cas = 0;
cout << "Which Case (1-5): ";
cin >> cas;
double Fo, alpha, w, t;
if (cas == 2) {
Fo = Y*k2;
}
else {
w = r*wn;
t = 0;
Fo = 0;
Fo = Y*sqrt((k2*k2 + pow((c2*w), 2)));
alpha = atan(-c2*w / k2);
}
//Static amplitude
staticamp = 0;
staticamp = Fo / keq;
double Xp = (Fo / keq) / (sqrt(pow((1 - r*r), 2) + pow((2 * dampratio*r), 2)));
double phi = atan((ceq*w) / (keq - m*w*w));
double xp = Xp*sin(w*t - phi);
double H, Td, Ftwall, Ftbase;
//Displacement Transmissiblity
Td = 0;
Td = (Fo / (Y*keq)) / (sqrt(pow((1 - r*r), 2) + pow((2 * dampratio*r), 2)));
//Frequanecy Response
H = 0;
H = 1 / (sqrt(pow((1 - r*r), 2) + pow((2 * dampratio*r), 2)));
//Force Transmissibilty to the bang
Ftbase = 0;
Ftbase = (Xp*sqrt(pow((k1 - keq*r*r), 2) + pow((c1*wn*r), r))) / (Y*k2);
//Force Transmissibilty to the wall
Ftwall = 0;
Ftwall = (Xp*sqrt((k1*k1) + pow((c1*r*wn), 2))) / (Y*k2);
if (cas == 5) {
cout << "\nCase: " << cas << endl << endl;
cout << "Wn: " << wn << endl;
cout << "Damping Ratio: " << dampratio << endl;
cout << "Amplitude: " << staticamp << endl;
cout << "Frequency Response: " << H << endl;
cout << "Phase Angle: " << phi << endl;
cout << "Displacement Transmissibilty: " << Td << endl;
cout << "Force Tranmissibility to the base: " << Ftbase << endl;
}
else {
cout << "\nCase: " << cas << endl << endl;
cout << "Wn: " << wn << endl;
cout << "Damping Ratio: " << dampratio << endl;
cout << "Amplitude: " << staticamp << endl;
cout << "Frequency Response: " << H << endl;
cout << "Phase Angle: " << phi << endl;
cout << "Displacement Transmissibilty: " << Td << endl;
cout << "Force Tranmissibility to the base: " << Ftbase << endl;
cout << "Force Transmissibilty to the wall: " << Ftwall << endl;
}
//*****************************Section 1.2 **********************************************
// 1.2 output for a range of driving frequencies
//input values for the case
cout << "Mass: ";
cin >> m;
cout << "c1: ";
cin >> c1;
cout << "c2: ";
cin >> c2;
cout << "k1: ";
cin >> k1;
cout << "k2: ";
cin >> k2;
cout << "Y: ";
cin >> Y;
//solve for the equivlent values
ceq = keq = 0;
ceq = c1 + c2;
keq = k1 + k2;
wn = 0;
wn = sqrt(keq / m); //natural frequency
dampratio = ceq / (2 * sqrt(m*keq)); // damping ratio
//Determine the Case
cas = 0;
cout << "Which Case (1-5): ";
cin >> cas;
double staticamp[200], Xp[200], xp[200], Fo[200], phi[200], w[200];
double alpha[200], Td[200], H[200], Ftbase[200], Ftwall[200], r[200];
r[1] = .1;
for (int i = 0; i<200; i++) {
if (cas == 2) {
Fo = Y*k2;
}
else {
w = r[i] * wn;
t = 0;
Fo = 0;
Fo = Y*sqrt((k2*k2 + pow((c2*w), 2)));
alpha[i] = atan(-c2*w / k2);
}
//Static amplitude
staticamp[i] = 0;
staticamp[i] = Fo / keq;
Xp[i] = (Fo / keq) / (sqrt(pow((1 - r[i] * r[i]), 2) + pow((2 * dampratio*r[i]), 2)));
phi[i] = atan((ceq*w) / (keq - m*w*w));
xp[i] = Xp*sin(w*t - phi);
//Displacement Transmissiblity
Td[i] = 0;
Td[i] = (Fo / (Y*keq)) / (sqrt(pow((1 - r[i] * r[i]), 2) + pow((2 * dampratio*r[i]), 2)));
//Frequanecy Response
H[i] = 0;
H[i] = 1 / (sqrt(pow((1 - r[i] * r[i]), 2) + pow((2 * dampratio*r[i]), 2)));
//Force Transmissibilty to the bang
Ftbase[i] = 0;
Ftbase[i] = (Xp*sqrt(pow((k1 - keq*r[i] * r[i]), 2) + pow((c1*wn*r[i]), r[i]))) / (Y*k2);
//Force Transmissibilty to the wall
Ftwall[i] = 0;
Ftwall[i] = (Xp*sqrt((k1*k1) + pow((c1*r[i] * wn), 2))) / (Y*k2);
//increment r
r[i + 1] = r[i] + .1;
}
ofstream Data(" 1.2 Case 1 .txt"); // File Creation to import in text file to graph
for (int i = 0; i > 200; i++) { //NEED TO CHANGE FILE NAME FOR NEW DATA SET
Data << r[i] << "," << H[i] << "," << phi[i] << "," << Td[i] << "," << Ftbase[i] << "," << Ftwall[i] << endl;
}
//************************* Section 2 ****************
cout << "\t\tSection 2" << endl << endl;
//input values for the case
cout << "Mass: ";
cin >> m;
cout << "c1: ";
cin >> c1;
cout << "c2: ";
cin >> c2;
cout << "k1: ";
cin >> k1;
cout << "k2: ";
cin >> k2;
cout << "r: ";
cin >> r;
cout << "Y: ";
cin >> Y;
//solve for the equivlent values
ceq = c1 + c2;
keq = k1 + k2;
wn = 0;
wn = sqrt(keq / m);
dampratio = ceq / (2 * sqrt(m*keq));
//Determine the Case
cout << "Which Case (1-5): ";
cin >> cas;
if (cas == 2) {
Fo = Y*k2;
}
else {
w = r*wn;
t = 0;
Fo = 0;
Fo = Y*sqrt((k2*k2 + pow((c2*w), 2)));
alpha = atan(-c2*w / k2);
}
//Static amplitude
staticamp = 0;
staticamp = Fo / keq;
Xp = (Fo / keq) / (sqrt(pow((1 - r*r), 2) + pow((2 * dampratio*r), 2)));
phi = atan((ceq*w) / (keq - m*w*w));
xp = Xp*sin(w*t - phi);
//Displacement Transmissiblity
Td = 0;
Td = (Fo / (Y*keq)) / (sqrt(pow((1 - r*r), 2) + pow((2 * dampratio*r), 2)));
//Frequanecy Response
H = 0;
H = 1 / (sqrt(pow((1 - r*r), 2) + pow((2 * dampratio*r), 2)));
//Force Transmissibilty to the bang
Ftbase = 0;
Ftbase = (Xp*sqrt(pow((k1 - keq*r*r), 2) + pow((c1*wn*r), r))) / (Y*k2);
//Force Transmissibilty to the wall
Ftwall = 0;
Ftwall = (Xp*sqrt((k1*k1) + pow((c1*r*wn), 2))) / (Y*k2);
if (cas == 5) {
cout << "\nCase: " << cas << endl << endl;
cout << "Wn: " << wn << endl;
cout << "Damping Ratio: " << dampratio << endl;
cout << "Amplitude: " << staticamp << endl;
cout << "Frequency Response: " << H << endl;
cout << "Phase Angle: " << phi << endl;
cout << "Displacement Transmissibilty: " << Td << endl;
cout << "Force Tranmissibility to the base: " << Ftbase << endl;
}
else {
cout << "\nCase: " << cas << endl << endl;
cout << "Wn: " << wn << endl;
cout << "Damping Ratio: " << dampratio << endl;
cout << "Amplitude: " << staticamp << endl;
cout << "Frequency Response: " << H << endl;
cout << "Phase Angle: " << phi << endl;
cout << "Displacement Transmissibilty: " << Td << endl;
cout << "Force Tranmissibility to the base: " << Ftbase << endl;
cout << "Force Transmissibilty to the wall: " << Ftwall << endl;
}
return 0;
}

Need advice on my quadratic formula functions

Okay The program compiles, but i am getting wrong output. Any help would be awesome. i do understand there are many other examples on this topic and i have looked at them all. None seemed to have help me clearly understand.
#include <iostream>
#include <cmath>
using namespace std;
double quadplus(float a, float b, float c);
double quadminus(float a, float b, float c);
int main()
{
double a, b, c;
double discriminant;
cout << "Please Enter variables for a, b, and c." << endl << endl;
cout << "Enter number for variable a." << endl << endl;
cin >> a;
cout << "Enter number for variable b." << endl << endl;
cin >> b;
cout << "Enter number for variable c." << endl << endl;
cin >> c;
discriminant = (b * b) - (4 * a * c);
if(discriminant == 0)
cout << quadplus(a,b,c) << endl;
else if(discriminant > 0)
cout << quadplus(a,b,c) << endl;
else if(discriminant < 0)
cout << quadminus(a,b,c) << quadplus(a,b,c) << endl;
return 0;
}
double quadplus(float a, float b, float c)
{
return ((-1 * b) + (sqrt(( b * b) - (4 * a * c))) / (2 * a));
}
double quadminus(float a, float b, float c)
{
return ((-1 * b) - (sqrt(( b * b) - (4 * a * c))) / ( 2 * a));
}
cout << quadplus << endl;
should probably be
cout << quadplus(a, b, c) << endl;
Also, if the discriminant is negative, your solutions will be
complex numbers of the form x + yi and your code doesn't properly account
for that. If discriminant != 0, you should probably print both roots.

To get pixel values of images

Below is the code which provides width,height and BGR values of 2 images.But the problem is until i close the first image i cant see the second image.What modifications to be made such that i can see both images at a time and get the all the pixel values.
1 . #include <cv.h>
#include<iostream>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
int main(int argc, char** argv[])
{
int width,height;
int i=0,j=0,k=3,l=3;
IplImage *img1 = cvLoadImage("E:/images.jpg");
cvNamedWindow("Image1:",1);
cvShowImage("Image1:",img1);
cout << "Width:" << img1->width << endl;
cout << "Height:" << img1->height << endl;
CvScalar s;
s=cvGet2D(img1,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);
cvWaitKey();
cvDestroyWindow("Image1:");
IplImage *img2 = cvLoadImage("C:/Users/Public/Pictures/Sample Pictures/Tulips.jpg");
cvNamedWindow("Image2:",2);
cvShowImage("Image2:",img2);
cout << "Width:" << img2->width << endl;
cout << "Height:" << img2->height << endl;
s=cvGet2D(img2,k,l); // get the (k,l) pixel value
printf("B1=%f, G1=%f, R1=%f\n",s.val[0],s.val[1],s.val[2]);
cvWaitKey();
cvDestroyWindow("Image2:");
cvReleaseImage(&img1);
cvReleaseImage(&img2);
return 0;
}
problem is with cvWaitKey()
try:
IplImage *img1 = cvLoadImage("E:/images.jpg");
cvNamedWindow("Image1:",1);
cvShowImage("Image1:",img1);
cout << "Width:" << img1->width << endl;
cout << "Height:" << img1->height << endl;
CvScalar s;
s=cvGet2D(img1,i,j); // get the (i,j) pixel value
printf("B=%f, G=%f, R=%f\n",s.val[0],s.val[1],s.val[2]);
IplImage *img2 = cvLoadImage("C:/Users/Public/Pictures/Sample Pictures/Tulips.jpg");
cvNamedWindow("Image2:",2);
cvShowImage("Image2:",img2);
cout << "Width:" << img2->width << endl;
cout << "Height:" << img2->height << endl;
s=cvGet2D(img2,k,l); // get the (k,l) pixel value
printf("B1=%f, G1=%f, R1=%f\n",s.val[0],s.val[1],s.val[2]);
cvWaitKey();
cvDestroyWindow("Image1:");
cvDestroyWindow("Image2:");
cvReleaseImage(&img1);
cvReleaseImage(&img2);

Resources