Software engineering with small work-random arithmetic (c + +)

Source: Internet
Author: User
Tags random seed

First, design ideas:

1. The main part of the program is the loop output, the number of topics by the user input;

2. Three integer variable +rand function to implement the random number arithmetic, one variable represents subtraction, and the other two are used as operands;

3. User experience: The topic is divided into three columns, neat and tidy spacing, and will not show a divisor of 0.

Since a winter vacation did not touch the programming, the biggest difficulty for me is not knowing the usage of the RAND function and the header file where it resides. I adjusted the page again after the basic ability was realized.  Added Srand ((unsigned) time (NULL)); 。 Because only the RAND function is used, the random number generated by each run of the program computer is fixed.

Second, the source code

#include "stdafx.h"

#include "iostream.h"

#include "Stdlib.h"

#include "time.h"

int main (int argc, char* argv[])

{

int a,b,c,n=1; A represents the operation symbol, b c is two numbers, n indicates the number of the question.

Srand ((unsigned) time (NULL)); The Srand () function produces a random seed that starts at the current time

cout<< "Please enter the number of question:";

cin>>n;

for (int i=1;i<=n;i++)

{

A=rand ()%4;

B=rand ()%100; b c is a two random integer within 100

C=rand ()%100;

cout<< "(" <<i<< ")" <<b;

Switch (a)

{

Case 1:cout<< "+" <<c<< "=\t\t";

Case 2:cout<< "-" <<c<< "=\t\t";

Case 3:cout<< "*" <<c<< "=\t\t";

Case 0:if (c==0) {i--;break;}

cout<< "/" <<c<< "=\t\t";

default:cout<< "+" <<c<< "=\t\t";

}

if (i%3==0)

cout<<endl;

}

cout<<endl;

return 0;

}

Iii. Results of operation

Software engineering with small work-random arithmetic (c + +)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.