0
0
0909090902020-12-14 23:10:25
C++ / C#
090909090, 2020-12-14 23:10:25

Why is the second number jumping?

I recently started learning C++ so maybe I'm dumb but I really don't understand)

#include <iostream>
using namespase std;

int main()
{
  int a, b, i;
  int sum;
  cout << "Zaday pervoe chislo\n";
  cin >> a;
  cout << Zaday znak\n";
  cin i;
  cout << Zaday vtoroe chislo\n"; <--перескакивает
  cin >> b;
  sum = a >> i >> b;
  cout << "Summa :" << sum << endl;<--сюда.
  return 0;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2020-12-14
@090909090

You have several errors in your code

#include <iostream>
 
using namespace std;


int main()
{
  int a, b;
  int sum;

  char i;

  cout << "Zaday pervoe chislo\n";
  cin >> a;

  cout << "Zaday znak\n";
  cin >> i;

  cout << "Zaday vtoroe chislo\n";
  cin >> b;

   if (i == '+')
      sum = a + b;
    if (i == '-')
      sum = a - b;
    if (i == '*')
      sum = a * b;
    if (i == '/')
      sum = a / b;

  cout << "Summa :" << sum << endl;
  return 0;
        
}

If we go back to your code and answer your question exactly, then the whole mistake is that you set the type of i as int, but the sign cannot be int, it is char

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question