I have to make a math problem using random numbers for a class and i keep getting this error
#include <iostream>
#include <cmath>
using namespace std;
// make a math problem with one function
// mab libs style
void Question1(){
int highestNumber;
int highnumber2;
double c;
string formula;
string a;
string b;
string tell;
cout << "Please choose the formula \n a. a + b \n b. a / b + 100\n c.a * 7 - 40 + b "; // they select formula
getline(cin, formula);
if (formula == "a"){
cout << "What is the highest number you want to use for this equation?\n";
cin >> highestNumber;
cout << "What is the next highest number you want to use for this equation?\n";
cin >> highnumber2;
cout << "Your formula is a + b and a = " << srand(time(0)) % highestNumber << " b = " << srand(time(0)) % highnumber2;//invalid operands to binary expression ('void' and 'int')
c = highestNumber + highnumber2;
cout << "Tell me when you get your answer ";
getline (cin, tell);
cout << "This is the answer " << c;
}
}
cout << "Your formula is a + b and a = " << srand(time(0)) % highestNumber << " b = " << srand(time(0)) % highnumber2;//invalid operands to binary expression ('void' and 'int')
You're using srand() incorrectly.
You use srand() exactly once and only once in your program to seed the pseudo-random number generator (typically at the start of your program).
You use rand() to generate a pseudo-random integral number between 0 and RAND_MAX. This is what you meant to use with your mod operator (%), but keep in mind this gives you a biased distribution.
cout << "Please choose the formula \n a. a + b \n b. a / b + 100\n c.a * 7 - 40 + b "; // they select formula
getline(cin, formula);
if (formula == "a"){
you ask the user to enter a string, and compare the string to a single letter
A better way to do is just compare the operation they enter