Hello. Most of the information is in the code.
And if you're wondering why I output it to the console window it's because I love watching my programs work.
//Program to work out how to use the numbers entered by the user can be used to make the number 24.
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <ctime>
usingnamespace std;
void populate(double numbers[], int limit);
int main()
{
srand((unsigned) time(0));
char operators[4] = {'+','-','*','/'};
double numbers[4];
cout << "Enter the 4 numbers:" << endl;
populate(numbers, 4);
double answer = 0;
while(answer != 24)
{
/* answer = [how do I do this?] Equation below goes here, but if I were to write:
numbers[0] operators[rand() % 4] numbers[1] etc
then it expects a ; because it's not an actual equation (no operators), but I can't
use actual operators because I'm randomly (well, kind of) generating them using an array.
My question is:
How exactly would I enter the below equation into answer? Does my code need a revamp? */
cout << numbers[0] << " " << operators[rand() % 4] << " ";
cout << numbers[1] << " " << operators[rand() % 4] << " "; // i.e. outputs 3 - 7 + 4 * 2 = answer
cout << numbers[2] << " " << operators[rand() % 4] << " ";
cout << numbers [3] << " = " << answer << endl;
}
cout << endl << "Done!";
char f;
cin >> f;
return 0;
}
void populate(double numbers[], int limit)
{
double input;
for(int i = 0; i < limit; ++i)
{
cout << i + 1 << ")"; //takes user input to specify the four numbers
cin >> input;
numbers[i] = input;
}
}