Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

107
Views
Usando declaraciones de cambio, con caracteres de terminación, en este caso '='

Estoy trabajando en un programa que toma valores y operandos y calcula el total de dichos valores. Este programa se repetirá hasta que el usuario ingrese '='.

Creo que estoy cerca, pero me falta algo para que funcione correctamente. Lo más probable es que no necesite el ciclo while, pero no estoy seguro.

Ejemplo de entrada de usuario:

 '6' '+' '5' '-' '3' '-' '7' '='

el total es 1

 int main() { float num1, num2; char change; float total; cout << "Welcome to your friendly neighborhood accumulator! Please input your expression, starting with an operand and type in '=' when completed." << endl; while(change != '='){ cin >> num1; cin >> change; cin >> num2; switch(change){ case '+': total = num1 + num2; break; case '-': total = num1 - num2; break; case '=': cout << total; break; default: cout << "Incorrect operator"; break; } } cout << "Thank you for using the accumulator!" << endl; return 0; }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

while(change != '='){ cin >> change; if(change != '='){ cin >> num2; } switch(change){ case '+': total = total + num2; break; case '-': total = total - num2; break; case '=': cout << total << endl; break; default: cout << "Incorrect operator"; break; } }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!