2
I’m trying to solve the Uri 1038 problem using switch
, apparently the values are merging, Item 3 for example, multiplying by 2 (5 x 2) returns the value 3. What I’m doing wrong here?
#include "pch.h"
#include <iostream>
using namespace std;
int main()
{
int i, q;
float valor;
cin >> i >> q;
switch (i) {
case 1:
valor = 4.00*q;
case 2:
valor = 4.50*q;
case 3:
valor = 5.00*q;
case 4:
valor = 2.00*q;
case 5:
valor = 1.50*q;
}
cout << "Total: R$" << valor;
}
I think the
switch
is running without pauses. Some were missing breaks in your code. See switch statement.– Woss
You’re squealing from the
break
's– user72726
@Andersoncarloswoss Caraca, I studied it yesterday and forgot about the break anyway. But even now with the right breaks in each condition continues to give the same result. Edit: I closed the VS and opened the project again and is now running ok, thanks!
– Raphael