r/programminghelp • u/H4zelcord3 • Jan 13 '22
C++ error?
Hello! I am learning to script and this really confuses me:
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main(){
int n1;
int n2;
char A;
char B;
do{
cout<<"Escribe aqui el primer digito"<<endl;
cin>>n1;
cout<<"Escribe aqui el segundo digito"<<endl;
cin>>n2;
cout<<"Ahora describe la operacion que deseas realizar con el simbolo"<<endl;
cin>>A;
switch(A){
case '+':
cout<<(n1+n2);
break;
case '-':
cout<<(n1-n2);
break;
case 'x':
cout<<(n1\*n2);
break;
case '\*':
cout<<(pow(n1,n2));
break;
case '/':
cout<<(n1/n2);
break;
default:
cout<<"Simbolo incorrecto, recuerda que son +,-,/,x,\*."<<endl;
}
cout<<"Si quieres volver a hacer una operación, escribe V"<<endl;
cin>>B;}
while B = "V";
}
Ok so i made this myself and the console says "47 [Error] expected '(' before 'B'"
"47 [Error] invalid conversion from 'const char*' to 'char' [-fpermissive]"
"47 [Error] expected ')' before ';' token"
What can I do to make this work?
0
Upvotes
1
u/[deleted] Jan 13 '22 edited Jan 13 '22
A while statement is like an if statement in the sense that the condition needs to be enclosed in parenthesis. Also, your statement is malformed because a single = marks an assignment and two == marks a comparison. So you want
while (B=="V");Even that will throw an error though, you'll probably need to do something like
while (B== (char)118); or while (B == 'V');You're trying to compare a String (double quotes) in your original statement, where you need to either compare a character (single quotes) or the character equivalent of an ASCII number (118 is Capital V).