hlp me in dis code!!
-
I write the folowing code which is taking RAM and Hard disk capacity from user by using structures and than saving it to a new file after the user complete entring data it is displaying data entered by the user by opening that file. Problm is that i want to ask the user to choose an option (y/n): If user enter y then your program again get the next record of computer specification i.e RAM capacity and hard disk capacity and store the information in file. And when the user enter n it will stop getting information and display the data of the file. For this i use do while construct but it is not working properly it is getting data but displays only last entry. plz tell me wat should i do. the code is: #include #include #include struct computerspec { int ram; int hdisk; }compuspec; void main() { char ch; do { //prompt the user to enter RAM capacity cout<<"Enter the RAM capacity"<>compuspec.ram; cout<>compuspec.hdisk; cout<
-
I write the folowing code which is taking RAM and Hard disk capacity from user by using structures and than saving it to a new file after the user complete entring data it is displaying data entered by the user by opening that file. Problm is that i want to ask the user to choose an option (y/n): If user enter y then your program again get the next record of computer specification i.e RAM capacity and hard disk capacity and store the information in file. And when the user enter n it will stop getting information and display the data of the file. For this i use do while construct but it is not working properly it is getting data but displays only last entry. plz tell me wat should i do. the code is: #include #include #include struct computerspec { int ram; int hdisk; }compuspec; void main() { char ch; do { //prompt the user to enter RAM capacity cout<<"Enter the RAM capacity"<>compuspec.ram; cout<>compuspec.hdisk; cout<
The problem in your code is that u are writing the file after the do while loop, and therefore if u write the file after the do-while construct it would write the last values. Write the values to the file in the do-while loop. After every time you obtain the values from the user write it to the file and then ask for the y/n thing. I mean just before this cout<