Question

C++ CSIT 139 Write a program that performs the following actions: 1) Generate a random integer...

C++ CSIT 139

Write a program that performs the following actions:

1) Generate a random integer number between 1 and 60, and save the number in a variable r.

2) Divide the random number by 3 and save the remainder in a variable a.

3) Divide the random number by 4 and save the remainder in a variable b.

4) Divide the random number by 5 and save the remainder in a variable c.

5) Perform these calculations: 40 x a + 45 x b + 36 x c and save the result in a variable d.

6) Divide d by 60 and save the remainder in a variable e.

7) Display, with appropriate labels, a, b, c, d, and e

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//C++ code

#include<iostream>
#include<stdlib.h>
#include<time.h>
using namespace std;
int main()
{
//seed rand with time
srand(time(NULL));
int r,a,b,c,d,e;
r=(rand()+1)%60;
//Getting remainders
a=r%3;
b=r%4;
c=r%5;
d=40*a+45*b+36*c;
e=d%60;
cout<<"r="<<r<<endl;
cout<<"a="<<a<<endl;
cout<<"b="<<b<<endl;
cout<<"c="<<c<<endl;
cout<<"d="<<d<<endl;
cout<<"e="<<e<<endl;
return 0;
}

//Ouput

code snapshot

Add a comment
Know the answer?
Add Answer to:
C++ CSIT 139 Write a program that performs the following actions: 1) Generate a random integer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT