When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
12 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main(){
string s;
cin >> s;
string p;
string q;
int i{0};
while(1){
if(s[i] == '+' || s[i] == '-' || s[i] =='*' || s[i] == '/')
break;
p += s[i];
++i;
}
int one = stoi(p);
while(1){
if(s[i] == '!') break;
char c = s[i];
while(1){
if(s[i] == '+' || s[i] == '-' || s[i] =='*' || s[i] == '/')
break;
++i;
q += s[i];
}
int two = stoi(q);
switch (c){
case '+':
one += two;
break;
case '*':
one *= two;
break;
case '-':
one -= two;
break;
case '/':
one /= two;
break;
}
}
cout << one <<endl;
return 0;
}
it doesn't work
i did work on it for a while ðŸ˜
So first of all, change your variable names
So they are easier to read and understand
using namespace std will import all of the symbols from std into the enclosing namespace. This can easily lead to name collisions, as the standard library is filled with common names: get, count, map, array, etc.
A key concern with using namespace std; is not what is imported now but rather what may suddenly be imported in the future.
While using namespace std; is alright for tiny projects, it is important to move away from it as soon as possible. Consider less intrusive options, if you insist on not using scope resolution:
// OK: *only* import std::vector
using std::vector;
// OK: namespace alias
namespace chr = std::chrono;
chr::duration x; ```
Why is "using namespace std;" considered bad practice? :stackoverflow: Example of error caused by "using namespace std" :stackoverflow: Yet another example of an error
yep
almost done
#include <iostream>
#include <cmath>
#include <string>
using namespace std;
int main(){
string s;
cin >> s;
string p;
string q;
int i{0};
while(1){
if(s[i] == '+' || s[i] == '-' || s[i] =='*' || s[i] == '/')
break;
p += s[i];
++i;
}
int one = stoi(p);
while(1){
char c = s[i];
while(1){
++i;
if(s[i] == '+' || s[i] == '-' || s[i] =='*' || s[i] == '/'|| s[i] == '!')
break;
q += s[i];
}
int two = stoi(q);
switch (c){
case '+':
one += two;
break;
case '*':
one *= two;
break;
case '-':
one -= two;
break;
case '/':
one /= two;
break;
if(s[i] == '!') break;
++i;
if(s[i] == '!') break;
--i;
}
}
cout << one <<endl;
return 0;
}
last thing i need is the break of the loop
nvm