通过你提供的材料,用c++编码如下,望指正!
/*
if Natalia's number of apples is x (x>0)
apples:the number of apple
extra:the number that Klaudia more tha Natalia
(apples>extra>0)
so
x+extra+x=apples
x = (apples-extra)/2
*/
#include
int main(int argc, char const *argv[]) {
int apples,extra; //apples:the number of apple extra:the number that Klaudia more tha Natalia
for (size_t i = 0; i < 10; i++) {
std::cin>>apples>>extra; //input
try{
//To determine whether the input is legal
if(apples<=0 || extra<=0 || apples
int Klaudia,Natalia;
Natalia = (apples-extra)/2; //calculate
Klaudia=Natalia+2;
std::cout<
}
catch(int e){
//ERROR
std::cerr << "ERROR! the number of applse is error.\n" << '\n';
}
}
return 0;
}
运行结果