Skip to main content
GameDev.net gamedev.net
🔒 Locked

c++ struct problem

Started by imam07 Mar 23, 2009 at 2:16 PM 4 replies 900+ views
Original Post
imam07
imam07
hi everyone , i'm new this forum.. iam using DEVC++, i writed cpp program about 'struct' but when i push F9(compile and run) this program running in miliseconds.in my early programs when i see this problem i write system("PAUSE"); before return0. what should i do? code: #include using namespace std; struct part { int modelnumber; int partnumber; float cost; }; int main() { part part1 = {6244,373,217.55F}; part part2; cout << "model"<<part1.modelnumber; cout<< "parca"<< part1.partnumber; cout << cost <<part1.cost <<endl; part2 = part1; cout << "model" << part2.modelnumber; cout << "parca"<< part2.partnumber; cout << "fiyatlar" part2.cost<< endl; return 0; }
sheep19
sheep19
#include <iostream>using namespace std;struct part{int modelnumber;int partnumber;float cost;};int main(){part part1 = {6244,373,217.55F};part part2;cout << "model"<<part1.modelnumber;cout<< "parca"<< part1.partnumber;cout << cost <<part1.cost <<endl;part2 = part1;cout << "model" << part2.modelnumber;cout << "parca"<< part2.partnumber;cout << "fiyatlar" part2.cost<< endl;return 0;}


The program does everything that you told it to and exits. It's just too fast. You have to make it pause just before it exits so you can see the result. So just add the line:
cin.get(); right before the return 0; statement.
imam07
imam07
thanks it works , anyway this program have some mistakes i fixed mistakes then i push it worked.
Zahlman
Zahlman
Quote:
Original post by imam07
hi everyone , i'm new this forum..
iam using DEVC++, i writed cpp program about 'struct' but when i push F9(compile and run) this program running in miliseconds.


You can:

- Set a breakpoint on the last line of the program, and run to the breakpoint.
- Run the program from a command window, outside the API.
- Run the program using a .bat file.
- Pause the program artificially, by waiting for user input (this is what imam07 shows). This should be taken out later, because usually the user will be annoyed by having to input something at the end (and it's bad for "utilities" that will be connected together in a batch script, because that user input will have to be simulated).
stonemetal
stonemetal
Was there something wrong with system pause? If it was working why throw it away?
Incidentally, have you thought about running your command line programs from the command line and avoiding the "problem" all together?
imam07
imam07
compiler ran with faulty code then it doesnt show any problem

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.