C++ не входит дваждыC++

Программы на C++. Форум разработчиков
Anonymous
 C++ не входит дважды

Сообщение Anonymous »

Код: Выделить всё

enter code here
Я делаю калькулятор, который работает с мнимыми числами. Когда я запускаю его в терминале, я могу поместить первые два входа, однако второй дает сбой. (Посмотрите на снимок экрана для справки). Вот мой обработчик с get_complex_input(), который работает в этой части и комплексном файле. .

Код: Выделить всё

#include 
using namespace std;
#pragma once

class Complex {
private:
float real;
float imaginary;

public:
Complex() : real(0), imaginary(0) {}

Complex(float r, float i) : real(r), imaginary(i) {}

Complex operator+(Complex rhs) {
return Complex(this->real + rhs.real, this->imaginary + rhs.imaginary);
}
Complex operator-(Complex rhs) {
return Complex(this->real - rhs.real, this->imaginary - rhs.imaginary);
}
Complex operator*(const Complex& other) const {
float new_real = (this->real * other.real) - (this->imaginary * other.imaginary);
float new_imaginary = (this->real * other.imaginary) + (this->imaginary * other.real);
return Complex(new_real, new_imaginary);
}

Complex operator/(const Complex& other) const {
float denominator = (other.real * other.real) + (other.imaginary * other.imaginary);
float new_real = ((this->real * other.real) + (this->imaginary * other.imaginary)) / denominator;
float new_imaginary = ((this->imaginary * other.real) - (this->real * other.imaginary)) / denominator;
return Complex(new_real, new_imaginary);
}

// Function to find the conjugate of a complex number
Complex conjugate() {
return Complex(this->real, -(this->imaginary));
}

// A helper function to print the complex number
void print() const {
if (imaginary >= 0)
cout 

Подробнее здесь: [url]https://stackoverflow.com/questions/79016239/c-not-being-in-input-twice[/url]

Вернуться в «C++»