Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to run a cpp file?

Status
Not open for further replies.

Karien

Technical User
May 4, 2004
2
NL
ArkM thank you for your fast reply.

Do you mean this is not the right place to ask such questions? Or should I be more specific?

You say it's operational environment (OS) topic. Where can I ask questions on this?

About my goal:
I wrote a program (.cpp), let's say to calculate something. But now I want to run it 10 times, using 10 different sets of input variables. Eg, first t=1, a=3, etc, but next run t=5, a=5. I do not want to open my cpp file 10 times, changes these variables and run the program. How can I do this?

Well, still not sure if I can ask this kind of questions here.. Thanks anyway.



 
please post your question in the appropriate thread. Do not start new threads in order to continue an old thread.

Ion Filipski
1c.bmp
 
Modify your cpp source code to include something like this

for instance,

Code:
#include <iostream>

using namespace std;

int main()
{
  int t; 
  int a;
  int result;
  char input; [green]//to store user input[/green]
  bool loop=true;

  while(loop)
  {
    cout<<"Enter the value of t: ";
    cin>>t;

    cout<<"Enter the value of a: ";
    cin>>a;

    [green]//perform your calculation here[/green]
     result = t+a;

     cout<<"The result is :"<<result<<endl;
     cout<<"You want to continue? (y/n): ";
     cin>>input;
     cout<<endl;

     if (input=='n' || input =='N')
        loop = false;
  }

  cout<<"Thank you for using the program."<<endl;
  return 0;
}
 
Btw, you are not running cpp file. When you compile and build your cpp, you get executable file (.exe). Thus, you are actually running an exe file.
 
Karien,
thank you for thank...
See posts above...
If you have a program (with main function) and the program can accept parameters via cmd line or from its stdin, you may write a new program (in Zech's sample style) then start this 'calculator' in a while loop via system() library function...
It seems Zech's pattern is more better...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top