0

I DON'T KNOW WHAT'S PROBLEM WITH MY CODE

#include<iostream> #include<cmath> using namespace std; int main()  {     string right_answer;     int score=0;          cout<<"Capital in Japan: ";     cin>>right_answer;     cout<<"Capital in Philippines: ";     cin>>right_answer;     cout<<"Capital in Vietnam: ";     cin>>right_answer;     cout<<"Capital in Taiwan: ";     cin>>right_answer;     cout<<"Capital in Australia: ";     cin>>right_answer;     if (right_answer=="Tokyo" || right_answer=="TOKYO" || right_answer=="tokyo"){         cout<<"The answer you entered is correct.\n";         score=score+1;     }          else{          cout<<"The answer you entered is wrong.\n";          score=score+0;     }     if (right_answer=="Manila" || right_answer=="MANILA" || right_answer=="manila"){         cout<<"The answer you entered is correct.\n";         score=score+1;     }          else{          cout<<"The answer you entered is wrong.\n";          score=score+0;     }     if (right_answer=="Hanoi" || right_answer=="HANO

7th Dec 2022, 3:23 PM
Armlink
Armlink - avatar
3 Answers
+ 5
It appears that you have an issue with your code where the value of right_answer is being overwritten in each iteration of the loop. As a result, the same answer is being checked against each of the capital cities. To fix this issue, you could store the answers in an array or a separate variable for each capital city. Then, you can check the answers against the corresponding capital city.
9th Dec 2022, 11:28 AM
Sadaam Linux
Sadaam Linux - avatar
+ 2
If you taking input in variable then it's previous value will be overridden by new value. So last input about "Capital in Australia ", will be exits. Previous values are just useless inputs.. Take a string array. string right_array[5]; next use array cin>>right_array[i++] ; // before intialize int i=0; Seems there are more mistakes.. Try changes, if you need.. Save code and share link.. This may help you, to share links 👇 https://www.sololearn.com/post/75089/?ref=app
7th Dec 2022, 3:34 PM
Jayakrishna 🇮🇳
0
#include<iostream> #include<cmath> using namespace std; int main()  {     string right_answer;     int score=0;          cout<<"Capital in Japan: ";     cin>>right_answer;     cout<<"Capital in Philippines: ";     cin>>right_answer;     cout<<"Capital in Vietnam: ";     cin>>right_answer;     cout<<"Capital in Taiwan: ";     cin>>right_answer;     cout<<"Capital in Australia: ";     cin>>right_answer;     if (right_answer=="Tokyo" || right_answer=="TOKYO" || right_answer=="tokyo"){         cout<<"The answer you entered is correct.\n";         score=score+1;     }          else{          cout<<"The answer you entered is wrong.\n";          score=score+0;     }     if (right_answer=="Manila" || right_answer=="MANILA" || right_answer=="manila"){         cout<<"The answer you entered is correct.\n";         score=score+1;     }          else{          cout<<"The answer you entered is wrong.\n";          score=score+0;     }     if (right_answer=="Hanoi" || right_answer=="HANOI" || right_answer=="hanoi"){       
7th Dec 2022, 3:23 PM
Armlink
Armlink - avatar