CSIT139 C++ Write a program that generates 3 random numbers, a, b, and c, betwee
ID: 3884767 • Letter: C
Question
CSIT139 C++
Write a program that generates 3 random numbers, a, b, and c, between 1 and 9 inclusively and then performs the following steps, in order, with only a single expression that uses the least number of parentheses:
1)Multiply a by 2
2)Add 3 to the product
3)Multiply the sum by 5
4)Add 7 to the product
5)To the sum add the second number b
6)Multiply the sum by 2
7)Add 3 to the product
8)Multiply the sum by 5
9)Add the third number c to the product
10)Subtract 235 from the sum
Finally, display the difference, abc
Without parentheses the expression is
5 x 2 x 5 x 2 x a + 3 + 7 + b + 3 + c - 235
Explanation / Answer
#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main(){
int a,b,c;
srand(time(NULL));
a = rand() % 9 + 1;
b = rand() % 9 + 1;
c = rand() % 9 + 1;
int result = (((((a*2 + 3) * 5 + 7) + b) * 2 + 3) * 5 + c) - 235;
cout << result << endl;
return 0;
}