如何继续此代码? [英] How do I continue this code?

查看:93
本文介绍了如何继续此代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个问题:

编写一个程序,接受用户的两个整数。然后它询问用户他想用这两个数字做什么。如果用户选择是



'A' - 添加两个数字



'B' - 减去第一个数字中的第二个数字



'C' - 将第一个数字乘以第二个数字



'D' - 将第一个数字除以第二个数字



'Q' - 结束操作



你的程序应继续接受这两个数字和用户选择,除非用户输入'Q'作为选择。



这是我的代码到目前为止:

  #include    <   iostream  >  
using namespace std;
#include < sstream >


int main()
{
int integar_1;
int integar_2;
int choice;
char ch;


cout<< 欢迎使用基础数学计算器程序。;
cout<< 此程序将采用两个整数。您可以从以下5个选项中进行选择,看看会发生什么!<< ENDL;

cout<< 输入积分并按enter.\\\
;
cin>> integar_1;
cout<< 输入另一个整数并按enter.\\\
;
cin>> integar_2;

cout<< 您输入了<< integar_1<< << integar_2<< << ENDL;

cout<< 在以下字符中选择:<< ENDL;
cout<< A-添加两个数字。\ n;
cout<< B-从第一个数字中减去第二个数字。\ n;
cout<< C-将第一个数字乘以第二个数字。\ n;
cout<< D-将第一个数字除以第二个数字。\ n;
cout<< Q-结束操作。\ n;
cin.get(ch);
{
if
}


return 0 ;

}





如何继续if语句说如果用户说A,那么添加数字等?然后,如何提示用户再选择2个数字并重新执行此过程,直到他们按Q?只是一个简短的例子将有所帮助,因为我可以做其余的事情!请用C ++语言!谢谢!

解决方案

想想



(1)围绕你的主要代码循环重复直到'Q'进入 http://www.cplusplus.com/forum/general/6014/ [ ^ ]



(2)而不是使用'if'看看这个 http://www.cprogramming.com/ tutorial / lesson5.html [ ^ ]

This is the question:
Write a program which accepts two integers from the user. Then it asks the user what he wants to do with those two numbers. If the user choice is

‘A’ – Add the two numbers

‘B’ – Subtract the second number from the first number

‘C’ – Multiply the first number by the second number

‘D’ – Divide the first number by the second number

‘Q’ – End the operation

Your program should continue to accept the two numbers and the user choice unless the user enters ‘Q’ as choice.

This is my code so far:

#include <iostream> 
using namespace std;
#include <sstream>


int main()
{
	int integar_1;
	int integar_2;
	int choice;
	char ch;
	

	cout << "Welcome to a Basic Math Calculater program.";
	cout << "This program will take two integars. You can then choose from the following 5 options to see what happens!" << endl;

	cout << "Enter an integar and press enter.\n";
		cin >> integar_1;
	cout << "Enter another integar and press enter.\n";
		cin >> integar_2;

		cout << "You entered " << integar_1 << " and " << integar_2 << "." << endl;

		cout << "Choose between the following characters:" << endl;
		cout << "A- Add the two numbers.\n";
		cout << "B- Subtract the second number from the first number.\n";
		cout << "C- Multiply the first number by the second number.\n";
		cout << "D- Divide the first number by the second number.\n";
		cout << "Q- End the operation.\n";
		cin.get(ch);
		{
			if 
		}


	return 0; 

}



How do I continue with the if statement to say that If the user says A, then to add the numbers and so on? And then how do I prompt the user to pick 2 more numbers and re-do the process until they press Q? Just a short example will be helpful because I can then do the rest! In C++ language please! and thank you!

解决方案

think about

(1) a loop around your main code for repeating until 'Q' is entered http://www.cplusplus.com/forum/general/6014/[^]

(2) rather than use 'if' look at this http://www.cprogramming.com/tutorial/lesson5.html[^]


这篇关于如何继续此代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆