I want to divide the two numbers read in one line
up vote
-3
down vote
favorite
I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.
I implemented this in C ++, but I could not divide the two numbers read in one line.
This is an example
-input :
123 451
-output :
321
This is my code
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
char input[8];
cin.getline(input,8,'n');
string compare1="";
string compare2="";
// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.
reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());
if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
c++
New contributor
add a comment |
up vote
-3
down vote
favorite
I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.
I implemented this in C ++, but I could not divide the two numbers read in one line.
This is an example
-input :
123 451
-output :
321
This is my code
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
char input[8];
cin.getline(input,8,'n');
string compare1="";
string compare2="";
// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.
reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());
if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
c++
New contributor
1
double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19
Why don't you simply useint
ordouble
instead ofstring
for the input?
– πάντα ῥεῖ
Nov 18 at 14:20
What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21
add a comment |
up vote
-3
down vote
favorite
up vote
-3
down vote
favorite
I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.
I implemented this in C ++, but I could not divide the two numbers read in one line.
This is an example
-input :
123 451
-output :
321
This is my code
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
char input[8];
cin.getline(input,8,'n');
string compare1="";
string compare2="";
// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.
reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());
if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
c++
New contributor
I have a school assignment. But I have not implemented some of the code.
After reading the three digits a and b in one line, read this numbers in reverse.
Finally, it is a matter of comparing two readings and outputting a large number.
I implemented this in C ++, but I could not divide the two numbers read in one line.
This is an example
-input :
123 451
-output :
321
This is my code
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(void){
char input[8];
cin.getline(input,8,'n');
string compare1="";
string compare2="";
// I want to parsing this input string(line) to compare1 / compare2
// but I can’t.
reverse(compare1.begin(), compare1.end());
reverse(compare2.begin(), compare2.end());
if(compare1.compare(compare2)<0){
cout<<compare2<<endl;
}else{
cout<<compare1<<endl;
}
return 0;
}
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
c++
c++
New contributor
New contributor
edited Nov 18 at 14:21
πάντα ῥεῖ
71.2k970133
71.2k970133
New contributor
asked Nov 18 at 14:18
Vincent VC
11
11
New contributor
New contributor
1
double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19
Why don't you simply useint
ordouble
instead ofstring
for the input?
– πάντα ῥεῖ
Nov 18 at 14:20
What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21
add a comment |
1
double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19
Why don't you simply useint
ordouble
instead ofstring
for the input?
– πάντα ῥεῖ
Nov 18 at 14:20
What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21
1
1
double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19
double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19
Why don't you simply use
int
or double
instead of string
for the input?– πάντα ῥεῖ
Nov 18 at 14:20
Why don't you simply use
int
or double
instead of string
for the input?– πάντα ῥεῖ
Nov 18 at 14:20
What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21
What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
You can make the part that you want to make
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
3
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
What is different between this and the code that is aftermain()
??
– drescherjm
Nov 18 at 18:59
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
You can make the part that you want to make
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
3
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
What is different between this and the code that is aftermain()
??
– drescherjm
Nov 18 at 18:59
add a comment |
up vote
1
down vote
accepted
You can make the part that you want to make
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
3
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
What is different between this and the code that is aftermain()
??
– drescherjm
Nov 18 at 18:59
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
You can make the part that you want to make
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
You can make the part that you want to make
bool next = false;
for(int i=0; input[i]!=''; i++){
if(input[i] == ' '){
next = true;
continue;
}
if(next){
compare2 += input[i];
}else {
compare1 += input[i];
}
}
answered Nov 18 at 14:19
yeregi
792
792
3
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
What is different between this and the code that is aftermain()
??
– drescherjm
Nov 18 at 18:59
add a comment |
3
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
What is different between this and the code that is aftermain()
??
– drescherjm
Nov 18 at 18:59
3
3
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
Huh what? Care to explain please.
– πάντα ῥεῖ
Nov 18 at 14:20
What is different between this and the code that is after
main()
??– drescherjm
Nov 18 at 18:59
What is different between this and the code that is after
main()
??– drescherjm
Nov 18 at 18:59
add a comment |
Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.
Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.
Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.
Vincent VC is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53361862%2fi-want-to-divide-the-two-numbers-read-in-one-line%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
double a, b; cin >> a >> b; cout << a/b;
– Matthieu Brucher
Nov 18 at 14:19
Why don't you simply use
int
ordouble
instead ofstring
for the input?– πάντα ῥεῖ
Nov 18 at 14:20
What is the code after main(). Your code format is bad but the line after return 0 is all that is in main. I was going to fix the formatting but when I see invalid code like this I just leave it alone.
– drescherjm
Nov 18 at 14:21