Question
please help!
Write a program that can be used as a math tutor for a young student. The program should display two random numbers to be add
0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have given you the code with comments,and also code images and the output, Hope this helps

CODE-

//Required libraries
#include <iostream>
#include <cstdlib>
#include <conio.h>
using namespace std;

// our main function
int main()
{
    //declaring variables
    int min,max;
    const int MIN=50;
    const int MAX=450;
    //using srand ,rand functions for new seed generation to generate random numbers every time,rand()%(max-min)
    //+min to get random number between max and min values
    srand(time(0));
    min=rand()%(MAX-MIN)+MIN;
    max=rand()%(MAX-MIN)+MIN;
    //converting integers to strings for the sake of equal size or not 
    string s1=to_string(min);
    string s2=to_string(max);
    //calculating lengths of the strings 
    int s1len=s1.size();
    int s2len=s2.size();
    //if lengths equal it will prints the below statements and ask user to hit enter to see the result
    if(s1len==s2len){
        cout<<"  "<<min;
        cout<<"\n";
        cout<<" +"<<max;
        cout<<"\n";
        cout<<" ----";
        cout<<"\n";
        cout<<"Press Enter to see the answer";
        //using cin.get function value if we hit enterbutton this will execute
        if(cin.get() == '\n')
        {
            cout<<"  "<<min;
            cout<<"\n";
            cout<<" +"<<max;
            cout<<"\n";
            cout<<" ----";
            cout<<"\n";
            cout<<"  "<<min+max;}
        }
        ////if lengths are not equal it will prints the below statements and ask user to hit enter to see the result

       else if(s1len==1){
        cout<<"    "<<min;
        cout<<"\n";
        cout<<" +"<<max;
        cout<<"\n";
        cout<<" ----";
        cout<<"\n";
        cout<<"Press Enter to see the answer";
         //using cin.get function value if we hit enterbutton this will execute
        if(cin.get() == '\n')
        {
            cout<<"    "<<min;
            cout<<"\n";
            cout<<" +"<<max;
            cout<<"\n";
            cout<<" ----";
            cout<<"\n";
            cout<<"  "<<min+max;}
        }
        else if(s1len==2){
        cout<<"   "<<min;
        cout<<"\n";
        cout<<" +"<<max;
        cout<<"\n";
        cout<<" ----";
        cout<<"\n";
        cout<<"Press Enter to see the answer";
         //using cin.get function value if we hit enterbutton this will execute
        if(cin.get() == '\n')
        {
            cout<<"   "<<min;
            cout<<"\n";
            cout<<" +"<<max;
            cout<<"\n";
            cout<<" ----";
            cout<<"\n";
            cout<<"  "<<min+max;}
        }
        else if(s2len==1){
        cout<<" "<<min;
        cout<<"\n";
        cout<<"   +"<<max;
        cout<<"\n";
        cout<<" ----";
        cout<<"\n";
        cout<<"Press Enter to see the answer";
         //using cin.get function value if we hit enterbutton this will execute
        if(cin.get() == '\n')
        {
            cout<<"    "<<min;
            cout<<"\n";
            cout<<" +"<<max;
            cout<<"\n";
            cout<<" ----";
            cout<<"\n";
            cout<<"  "<<min+max;}
        }
    return 0;
}

CODE and OUTPUT images.

main.cpp 1 2 //Required libraries 3 #include <iostream> 4 #include <cstdlib> 5 #include <conio.h> 6 using namespace std; 7 8

main.cpp 24 25 26 27 - 28 29 30 31 32 33 34 35 36 37 - 38 39 40 41 42 43 44 45 46 47 int silen=s1.size(); int s2len=s2.size()

coutくく main.cpp 44 45 46 47 48 <<min-max; } } II//if Lengths are not equal it will prints the below statements and ask user t

לס == main.cpp 0 70 71 72 73 74 75 76 77. 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 couc cout<< + (max; cout<<\n; cout<

main.cpp 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 } 107 } else if(s2len==1){ cout<< <<min;

note-some comments are not clear due to less time .

Add a comment
Know the answer?
Add Answer to:
please help! Write a program that can be used as a math tutor for a young...
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
  • Write a program that can be used as a math instructor for a young student. The...

    Write a program that can be used as a math instructor for a young student. The program should display two random numbers to be added, such as: 247 + 129 The program should then pause while the student works on the problem. When the student is ready to check the answer, he or she can press a key and the program will display the correct solution: 247 +129 346

  • MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random...

    MUST BE PROCEDURAL CODE, DO NOT USE GLOBAL VARIABLES. Write a program in C++that generates random words from a training set as explained in the lectures on graphs. Do not hard-code the training set! Read it from a file. A suggested format for the input file: 6 a e m r s t 10 ate eat mate meet rate seat stream tame team tear Here are some suggestions for constants, array declarations, and helper functions #include <iostream> #include <fstream> #include...

  • guys can you please help me to to write a pseudo code for this program and...

    guys can you please help me to to write a pseudo code for this program and write the code of the program in visual studio in.cpp. compile the program and run and take screenshot of the output and upload it. please help is really appreciated. UTF-8"CPP Instruction SU2019 LA X 119SU-COSC-1436- C Get Homework Help With Che X Facebook -1.amazonaws.com/blackboard.learn.xythos.prod/584b1d8497c84/98796290? response-content-dis 100% School of Engineering and Technology COSC1436-LAB1 Note: in the instruction of the lab change "yourLastName" to your last...

  • Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should ge...

    Problem: Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display “heads.” If the random number is 2, the function should display “tails.” Demonstrate the function in a program that asks the user how many times the coin should be tossed and then simulates the tossing of the coin that...

  • Instructions: Consider the following C++ program. At the top you can see the interface for the...

    Instructions: Consider the following C++ program. At the top you can see the interface for the Student class. Below this is the implementation of the Student class methods. Finally, we have a very small main program. #include <string> #include <fstream> #include <iostream> using namespace std; class Student { public: Student(); Student(const Student & student); ~Student(); void Set(const int uaid, const string name, const float gpa); void Get(int & uaid, string & name, float & gpa) const; void Print() const; void...

  • Topics: Arrays in C. For this assignment, you will write a C program that uses its...

    Topics: Arrays in C. For this assignment, you will write a C program that uses its first command line parameter to compute and display a histogram of characters that occur in it. Requirements: Your program must compile and run correctly using the gcc compiler on ale. You must write the corresponding function definitions for the following function prototypes: // set all elements of the histogram to zero void init_histogram(int histo[]); // construct the histogram from string void cons_histogram(char string[], int...

  • Write a C++ program to display workers schedule for a company. To accomplish this (1) Write...

    Write a C++ program to display workers schedule for a company. To accomplish this (1) Write a struct Time with attributes (at least) : hours, minutes and seconds. Add other functions or attributes you need to get the job done (2) Write a class Schedule with attributes : Day of week, start_time, end_time and activity. Schedule should have at least (a) Display to display the schedule (b) Length to return the duration of the schedule (ie end_time - start_time), (c)...

  • there is a function to create two random numbers between 1 and 25 and a function...

    there is a function to create two random numbers between 1 and 25 and a function to add them together. add the prototypes correctly, call them from main correctly and output the results. The three functions should be subtractNumbers, multiplyNumbers, and divideNumbers. Remember that division won't always yield an integer so be sure to take care of that issue within the function (don't change the variable declarations). Don't change the code that I've given you. Follow the same pattern. #include...

  • Can you help us!! Thank you! C++ Write a program that can be used by a...

    Can you help us!! Thank you! C++ Write a program that can be used by a small theater to sell tickets for performances. The program should display a screen that shows which seats are available and which are taken. Here is a list of tasks this program must perform • The theater's auditorium has 15 rows, with 30 seats in each row. A two dimensional array can be used to represent the seats. The seats array can be initialized with...

  • I need a c++ code please. 32. Program. Write a program that creates an integer constant...

    I need a c++ code please. 32. Program. Write a program that creates an integer constant called SIZE and initialize to the size of the array you will be creating. Use this constant throughout your functions you will implement for the next parts and your main program. Also, in your main program create an integer array called numbers and initialize it with the following values (Please see demo program below): 68, 100, 43, 58, 76, 72, 46, 55, 92, 94,...

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