C++ :: Population Program - Won't Execute
May 20, 2012
I'm new to C++ and am trying to create a program to solve the problem as described in this image: [URL] .....
Here's my code. It fails to execute the main part of the problem (years, population of A & B) but works well in recognizing errors (if PopA >PopB or if growth rate of PopA<PopB)
Code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
string city1, city2;
[Code] .....
View 1 Replies
ADVERTISEMENT
Feb 22, 2015
Write a program that will predict the size of a population of organisms. The program should ask the user for the starting number of organisms, their average daily population increase (as a percentage), and the number of days they will multiply. A loop should display the size of the population for each day.
Input Validation: Do not accept a number less than 2 for the starting size of the population. Do not accept a negative number for average daily population increase. Do not accept a number less than 1 for the number of days they will multiply.
My code works fine just up until the end.
#include <iostream>
using namespace std;
int main() {
int organisms = 0, growthRate, rate, days, amount = 0;
//int x; //for loop
[Code] .....
View 1 Replies
View Related
Apr 18, 2014
System();is bad, I get that. Is there another way, that works across platforms I can use to execute an external program. If not, is there a windows specific way.
View 2 Replies
View Related
Aug 13, 2012
i wrote the c program for command line arguments,but i don't know how execute c program through command prompt
i did like this
d: cin>
then how should i proceed for execution
View 1 Replies
View Related
Jun 9, 2013
I have a Third Party MS-DOS program, RUN.EXE
RUN.EXE do the following:
1. Read FILE.INP as input file and run its code execution.
2. When finish, RUN.EXE will produce FILE.OUT as the output of its code execution.
3. However, if calculation made in the code execution come to unsatisfied condition, RUN.EXE will terminate without producing FILE.OUT or partially produce FILE.OUT.
I want to write a program using MFC which I can set a several input case. The program should be able to:
1. Call RUN.EXE.
2. Wait for RUN.EXE to exit.
3. Continue with other code.
I can't modified RUN.EXE. I can't have RUN.EXE callback my program to let know it finish its work.
Are there any functions to call RUN.EXE, a MS-DOS program? Are there any way for the program to check if RUN.EXE finish its work and exited?
View 4 Replies
View Related
Feb 3, 2014
I am trying to create a program that would execute a foreground process. I have this code for the foreground process
Code:
#include <stdio.h>
#include <signal.h>
int main() {
int temp;
printf("We are in the current program
[Code] ....
And this is my main program
Code:
#include <unistd.h>
#include <signal.h>
#include <stdio.h>
int main() {
signal(SIGINT, SIG_IGN);
[Code] ....
My main program stops executing after the process "./scanf" executes and there fore does not print the line "How are You"...
I want to main program to continue executing after "./scanf" finishes. How to achieve that?
View 2 Replies
View Related
Feb 18, 2013
The problem is with the first "Type and Run," where the code looks like this:
Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>
void do_heading(char *filename);
int line = 0, page = 0;
[Code] ....
I am using the gcc compiler in Ubuntu 12.04 LTS and I get the following error:
Code:
print_it.c: In function "main":
print_it.c:36:15: error: "stdprn" undeclared (first use in this function)
print_it.c:36:15: note: each undeclared identifier is reported only once for each function it appears in
print_it.c: In function "do_heading":
print_it.c:49:16: error: "stdprn" undeclared (first use in this function)
I was told that "stdprn" can be recognised by a DOS based compiler and the book says I can try using "stdout" instead. It looks like this now:
Code:
/* print_it.c--This program prints a listing with line numbers! */
#include <stdlib.h>
#include <stdio.h>
void do_heading(char *filename);
int line = 0, page = 0;
[Code] .....
It compiled OK with the gcc compiler but I only get this when I run the program:
Code:
Proper Usage is:
print_it filename.ext
I am not sure whether I should continue looking into this but even when I tried compiling and running it on Windows, the .exe file won't even launch. The other ones do but this first one doesn't.
Questions:
1. What should be done to make this program run?
2. Even though the book says "don't care" if the reader does not understand the items (It's Day 1/Lesson 1), I would still like it to run as I don't want to experience compiling and running problems in the future. Should I even bother doing this section of the book or is it obsolete and should be skipped?
View 6 Replies
View Related
May 8, 2012
My code in c++ is
#include<iostream.h>
main()
{int a[10],x[5];
a[-7]=15;
x[5]=20;
cout<<x[-5];
}
View 2 Replies
View Related
Mar 12, 2014
I'm supposed to store the value of a countrys population. Then gather out the percentage that countrys population holds when compared with the global population.
Anyway here's the code:
Code:
#include <iostream>
long swe_pop = 9644864;
int main ()
[Code] .....
The result I'm getting is 0%.
I was under the impression that long (or long long) integers could hold high values. And that I could then divide these and answer with a float type value. Giving space for the decimals.
View 3 Replies
View Related
May 15, 2014
I'm trying to analyze Population Dynamics. I found some articles and read them but what kind of model i need to use. I tried Forest Fire model but i failed in modificating.
#include <stdio.h>
#include <stdlib.h>
#define MaxPopulation 10000
#define MaxChildren 10
#define maxAge 70
#define ranf() ((double) random()/(double)RAND_MAX)
View 7 Replies
View Related
Mar 14, 2013
Is it possible to write a program such that it will automatically execute the function in queue base on their priority even if user programmed it randomly?
Code:
function1(){ very_important; }
function2(){ important; }
function3(){ less_important; }
int main() { // Programmed by user
function3;
function1;
function2;
//Output: Program will execute function1, 2 and lastly 3.
}
View 2 Replies
View Related
Aug 13, 2014
I compiled/built a code I had and made an executed file but when i click on it the CMD closes instantly. Is there anyway to keep this open?
View 10 Replies
View Related
Feb 17, 2013
For easier debugging, I would like to execute an own (predefined) function while beeing in a breakpoint (e.g. print some variables to a file).
Does there exists such a feature?
e.g.
- run program to a breakpoint
- a) press a keyboard-function-key (which calls that predefined function)
- b) or hover with cursor over a variable (and modify somehow the routine which shows its content on the screen)?
View 2 Replies
View Related
Aug 26, 2014
i need to create an small windows form, with some buttons, and then those buttons will "exectute" an action on a remote webserver.
Im searching with http requestings and didn't find nothing useful for what i need.
The basic thing is that i just need to press "EXECUTE" and then c# will press one link in the Webserver. I do not need any feedback from the page. I just need that C# execute a link like localhost/startbackup.php then the actions from the startbackup.php will run.
I do not need any information regarding if the page was successful executed or not, or even if it opens one window. Nothing.
View 1 Replies
View Related
Feb 14, 2012
I'm wondering whether it's possible to implement MPI to execute a process in parallel from deep within a C++ solution.
I've created a solution on VS2005 that links to several static libraries, and within one of these libraries there is a set series of tasks that require execution many times - they're independent so I'd like them to execute them using MPI if possible to speed up the run time.
The pseudo-code is:
Code:
for(i = 0; i < n; i++) // n is number of times to execute process {
PerformTask(data[i]); // perform the tasks required for each iteration of process
}
So, instead of conducting the tasks within PerformTask() in series n times, I want to split the array data between multiple processes such that they can each be allocated an even proportion of data to perform the tasks on. Pretty textbook reason for wanting MPI, right?
Now, I've read up and understood the basics of MPI implementation, but all the examples I've seen are called within the main() function of the program. But I need to do all this from within a static library, is this possible?
I've made some early attempts at implementing this, but get an error indicating the process wasn't initialised: "Error encounted before initializing MPICH", which I assumed would be due to trying to make the MPI calls outside of the main() function.
View 4 Replies
View Related
Mar 10, 2013
I have a condition and I would like to instead change the condition so that it would execute the previous statements after else statement.
It seems hard to explain but I'll try my best to illustrate anyway
if (condition)
<statement1>
else
<statement2>
So I would like to change the condition so that
if (condition)
<statement2>
else
<statement1>
And the condition is
Code:
if(!lightStateAtNextLink || !bIsLightEnAtConnection && nLinkNext.IndexToAttachedNode() != pVeh->_.stAutopilot.m_dwNextNode || bIsLightEnAtConnection && nLinkNext.IndexToAttachedNode() == pVeh->_.stAutopilot.m_dwNextNode)
And I have changed that to this. Is this correct?
Code: if(lightStateAtNextLink && bIsLightEnAtConnection || nLinkNext.IndexToAttachedNode() == pVeh->_.stAutopilot.m_dwNextNode && !bIsLightEnAtConnection || nLinkNext.IndexToAttachedNode() != pVeh->_.stAutopilot.m_dwNextNode)
View 5 Replies
View Related
Jun 17, 2014
I'm working on a project that's got a lot of moving parts, from feedback from a position sensor to real-time video editing. The script that runs the sensor is in C++, and the API for the video editing software (vMIX) is executed with HTTP protocol. I'm hoping to use that C++ script to control the video software (as some of the editing is dependent on particular feedback from the sensor), and wanted to see how to execute a HTTP command from a C++ script.
View 3 Replies
View Related
Nov 10, 2014
I'm trying to create a program that will show what the 12th digit of a UPC code would be. However, once the user enters the first 11 digits the program doesn't execute the last call of printf. The program compiles with no issues.
Code:
#include<stdio.h>
int main() {
int o1, e2, o3, e4, o5, e6, o7, e8, o9, e10, o11, oddsum, evensum, twelve;
printf
[Code] .....
View 9 Replies
View Related
Feb 11, 2013
Im going through a C tutorial and im going to create a Database as part of the course. Im just in the very beginning of the project so its a very simple program so far.
Code:
#include<stdio.h>
main(){
/*Variabler for att lagra information om skiva*/
char title[200];
char artist[100];
int tracks;
int price;
[Code] ....
The first switch case statement takes me to the menu of choice, 1 or 2. However, chosing menu option one and trying to input a title or artist name, the program crashes.
Next, going into menu option 2 and then trying to print out, for example, title nothing happend. The process just ends.
Again, im sure this simple prototype is full of errors ....
View 1 Replies
View Related
May 20, 2013
I want to execute one command using batch file but non of below code is working. Following are codes for executing batch file, First trial:-
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if( !CreateProcess( NULL,
"cmd /C sa.bat",
[Code]....
Non of above code is working for me but when open same batch file using double click it work like I expected.
Following is content of the file,
C:windowssystem32wusa /uninstall /kb:2718695 /quiet /forcerestart
Command use to uninstall internet explorer 10 an install internet explorer9.
View 2 Replies
View Related
Mar 5, 2014
I have simple LCd_call function . I am calling this function from main . I wanted to call this function once. problem i am facing here, When lcd_call function being called. It enter the cases but instead of staying paricular case it coming back and starting case 1 iteslf . for every 6s it change the case to 1:
View 2 Replies
View Related
Dec 21, 2012
How to set execute statement in the end of sql, Attach is my code:
private void InsertintoDB() {
string strSQL = "";
string strDBType = System.Configuration.ConfigurationManager.AppSettings["DBType"];
string strConn = System.Configuration.ConfigurationManager.AppSettings["DB_CONNECTION_STRING1"].ToString();
string strInsertTableName_Sql = "CIMMGR.[dbo].ANSDATA";
[Code] ....
View 2 Replies
View Related
Jul 25, 2014
Code:
void Arrival_MainThread::Body () {
t1 = new boost::thread((Arrive_Fctor()), 2);
t2 = new boost::thread((Arrive_Fctor()), 10000);
t3 = new boost::thread((Arrive_Fctor()), 3000);
Code:
class Arrive_Fctor {
public:
void operator()(int mean) {
m_Arrivals = new Arrivals(mean);
m_Arrivals->Activate();
#ifndef NO_RESOURCE
[code].....
The order of arrivals always appear as 3,2,1 it can't be 1,2,3 or 3,1,2 or something like that?
The body method is called when m_Arrival->Activate() is executed, and it is running as an independent thread.
View 4 Replies
View Related
Oct 23, 2013
I'm working on a Hash Table implementation and after fixing all the errors and finally getting it to compile and link correctly, I am met with a black screen upon execute.
main.cpp
#include <stdio.h>
#include <string.h>
[Code]....
I tried inserting a debug statement in the main() function to see, and it wouldn't even print out the message "debug me" on the screen.
I am using Code::Blocks on Windows with the mingw32-g++.exe compiler. Here is my build log:
mingw32-g++.exe -Wall -g -c D:MediaDesktopHashElement.cpp -o objDebugElement.o
mingw32-g++.exe -Wall -g -c D:MediaDesktopHashHashTab.cpp -o objDebugHashTab.o
mingw32-g++.exe -Wall -g -c D:MediaDesktopHashmain.cpp -o objDebugmain.o
mingw32-g++.exe -Wall -g -c D:MediaDesktopHashStudent.cpp -o objDebugStudent.o
mingw32-g++.exe -o binDebugHash.exe objDebugElement.o
objDebugHashTab.o objDebugmain.o objDebugStudent.o -mwindows
Output size is 1.06 MB
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 0 warnings (0 minutes, 2 seconds)
View 11 Replies
View Related
Feb 17, 2013
I would like to implements something in my code that clears the value of my variables when the user closes the console. How to do that or the program clears the values automatically?
View 3 Replies
View Related
Oct 24, 2014
I have to write a C++ program that picks a random number between 0 and 49. If the number is even lets say 30, then the computer will display 30, 32, 34, 36... all the way till 100, if its odd lets say 17, then the computer will display 17, 19.. till 99. I got the computer picking a random number, I just can't figure out how to display every other number using a for loop statement. Here's my code for random number generator:
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main()
[Code] ....
View 4 Replies
View Related