Program compiles but does not run

Sep 29, 2014 at 4:39pm
I made a program that does basic math operations but will not run. When i hit compile it tells me that the build succeeded but it does not run. Any input would help.
P.S. if i click build a lot of times it eventually says that there is 1 up-to-date error, and i don't know what that means. Thanks!

include <iostream>
#include <cstdlib>
#include <ctime>
#include <cmath>
using namespace std;

int main()
{
int answerA, //Answer to the addition problem
answerS, //Answer to the subtraction problem
answerM, //Answer to the multiplication problem
choice; //User's choice of program
int random1, //Made to create numbers in interval
random2; //Made to create numbers in interval
int solveA, //Answer input
solveS, //Answer input
solveM; //Answer input
do
{ // This will display the main menu
cout << "Math Tutor Version 3 - Main Menu \n";
cout << "1. Addition \n";
cout << "2. Subtraction \n";
cout << "3. Multiplication \n";
cout << "4. Quit Program \n\n";
cout << "Please enter your choice (1-4)\n";
cin >> choice;

while ((choice < 1) || (choice > 4))
{
cout << "Please make an option between (1-4)\n";
cin >> choice;
}
// Calculating the random number
random1 = (rand() % 50) + 10; // Set up to interval of 10-50
random2 = (rand() % 49) + 10;
// Part for choice 1
if (choice == 1)
{
answerA = random1 + random2;
cout << "Addition Problem: \n";
cout << random1 << endl;
cout << "+ " << random2 << endl;
cout << "_________" << endl;
cout << "Your answer: ";
cin >> solveA;
if (solveA == answerA)
cout << answerA << "<---- you got the correct answer!\n";
else
cout << answerA << "<---- was the correct answer.\n";
}
// Part for choice 2
else if (choice == 2)
{
answerS = random1 - random2;
cout << "Subtraction Problem: \n";
cout << random1 << endl;
cout << "- " << random2 << endl;
cout << "_________" << endl;
cout << "Your answer: ";
cin >> solveS;
if (solveS == answerS)
cout << answerS << "<--- you got the correct answer.\n";
else
cout << answerS << "<--- was the correct answer.\n";
}
// Part for choice 3
else if (choice == 3)
{
answerM = random1 * random2;
cout << "Multiplication Problem: \n";
cout << random1 << endl;
cout << "* " << random2 << endl;
cout << "_________" << endl;
cout << "Your answer: ";
cin >> solveM;
if (solveM == answerM)
cout << answerM << "<--- you got the correct answer.\n";
else
cout << answerM << "<--- was the correct answer.\n";
}
}
// The option to quit
while (choice != 4);
cout << "Thanks for using my program!" << endl;


return 0;
}


******Also i tried compiling older codes but they know longer run as well, do i need to update or something, im using VS2013
Last edited on Sep 29, 2014 at 4:56pm
Sep 29, 2014 at 4:47pm
Try posting the code on here. Use the <>code tags when posting it. Without the code, we know nothing of what's in your code or what you are trying to do.
Sep 29, 2014 at 4:56pm
It's been updated
Sep 29, 2014 at 5:35pm
Compile means to create the program. If you want it to execute, then you have to execute it. Open a command prompt, navigate to the destination folder that your binary was created in (cd is the Windows command to change your directory) and then enter the name of your executable. What happens then?
Sep 29, 2014 at 5:48pm
It's all good now thanks!. Another question though as you can see from the code above im trying to use random numbers in the equation but each time it's run it starts with the same combination 53 + 51 but i want it to have different numbers each time and be between 10 and 50. What can i do to fix that?
Sep 29, 2014 at 6:01pm
You have to set a seed using srand. One way is to do srand(time(NULL)). There are definitely better ways using C++11's features, though, but for your purposes, doing srand is fine.
Sep 29, 2014 at 6:05pm
Also remember to only call srand() once per instance of the application. Otherwise you're essentially resetting your seed.
Sep 29, 2014 at 6:25pm
// Calculating the random number
srand(time(0)); // Used to get random number each time the program is used
random1 = (rand() % 50) + 10; // Set up to interval of 10-50
random2 = (rand() % 49) + 10;



It works well guys, and my final question is how to get the random number to be in the interval of 10-50, I thought the way I have it above was proper but I guess not.
Sep 29, 2014 at 7:11pm
This line is not correct:
random1 = (rand() % 50) + 10; // Set up to interval of 10-50
The rand() % 50 part will yield a number between 0-49 inclusive. Adding 10 to this result yields a range of 10-59 inclusive.

To get a range of 10-50, you must note that 10-50 inclusive is 41 unique numbers. rand() % 41 yields a number in the range of 0-40 inclusive, and this is the range to which you should add 10.
Sep 29, 2014 at 7:20pm
Thanks everyone I really appreciate it!!
Topic archived. No new replies allowed.