-2

I'm doing a tax calculator in C ++ but I have an error It is supposed to enter several data: Type of vehicle, date and model. But the program asks me only one before pause and does not go ahead.

It is assumed that the operation is as follows: You enter a type of vehicle, then the date of issuance, and finally its price.

Given these data, the program is supposed to calculate the percentage of tax that must be included.

But as I said, the program is paused before asking the second data, the year.

This is the code

#include <iomanip>
#include <iostream>

using namespace std;

int main(){

std:string a;//tipo
int b;//año
double c;//precio
char d;//resultado

cout << "Ingrese el tipo:";
cin >> a;

cout << "Ingrese el año:";
cin >> b;

cout << "Ingrese el precio:";
cin >> c;

if (a = "automovil" && b <= 1980){
   d = c*100/3.3;
   }else if ( a == "automovil" && b <= 1990){
         d = c*100/5.5;
   }else if ( a == "automovil" && b <= 2000){
         d = c*100/7;
   }else if ( a == "automovil" && b <= 2010){
         d = c*100/10;
   }else if ( a == "camioneta" && b <= 1980){
         d = c*100/3.3;
   }else if ( a == "camioneta" && b <= 1990){
         d = c*100/5.5;
   }else if ( a == "camioneta" && b <= 2000){
         d = c*100/7;
   }else if ( a == "camioneta" && b <= 2010){
         d = c*100/10;
   }else if ( a == "camion" && b <= 1980){
         d = c*100/3.3;
   }else if ( a == "camion" && b <= 1990){
         d = c*100/5.5;
   }else if ( a == "camion" && b <= 2000){
         d = c*100/7;
   }else if ( a == "camion" && b <= 2010){
         d = c*100/10;
   }else if ( a == "volqueta" && b <= 1980){
         d = c*100/3.3;
   }else if ( a == "volqueta" && b <= 1990){
         d = c*100/5.5;
   }else if ( a == "volqueta" && b <= 2000){
         d = c*100/7;
   }else if ( a == "volqueta" && b <= 2010){
         d = c*100/10;
   }

cout << d;

return 0;
}

any suggestions?

3 Answers3

2

Some issues with your code: to test for equality use the == operator (not the assignment = operator).

E.g.

if (a = "automovil" && b <= 1980)

...
else if ( a = "automovil" && b <= 1990){

Should be

if (a == "automovil" && b <= 1980)

...
else if ( a == "automovil" && b <= 1990){

And your last line expects you to write something to standard input. As was in the comments I think if you really wanted to test your calculated d value you should print it to standard output like so:

cout << d << endl;

Because what is currently happening is you are overwriting the d value that you calculated once you type something into standard input.

ifma
  • 3,673
  • 4
  • 26
  • 38
1

there are several error in your code, forst of all it seems unlikely that you should declare "a" as a char, from your code it seems like it should be instead a std::string. you should also note that the following code is wrong

if (a = "automovil" && b <= 1980){

you should use

if (a == "automovil" && b <= 1980){
Marco Belli
  • 113
  • 7
0

There is a bunch of mistakes in your code:

First, you need to declare a and b as std:string and not char.

Second, you need to use == to compare two variables and not = which is the assignment operator.

Third, you need to cout << d; at the end of your program and not cin >> d;

Khalil Khalaf
  • 9,259
  • 11
  • 62
  • 104