PDA

View Full Version : HOW to do this Qt ?



Petr_Kropotkin
31st January 2010, 17:23
Here is a code snipet of calculating the average and displaying it on the console


include <iostream>
include <iomanip>
using std::cout;
using std::cin;
using std::setw();
int main()
{
int number,sum=0;
float mean=0;
for (int i=1;i<5;++i)
{
cout<<"\nenter number->";
cin>> number;
sum=+number;
}
mean= sum/5;
cout <<"mean="<<setw(2)<<mean;
}

Running in console mode

Enter number->23
Enter number->5
Enter numer-> 6
Enter number->123
Enter number->4
mean=32.2

How could this be done in a GUI with tthe same results ?
Is it possible ?

franz
31st January 2010, 18:33
You already have a piece of code accepting input (the one with the line edit). Implementing the behaviour you want is something you should try yourself first.

squidge
31st January 2010, 19:04
Use QtDesigner to put 5 lineEdit's onto a form, along with a submit button and a label. Make the submit button calculate the average and put it in the label.