Help me plz | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
5th Dec 2020, 3:15 PM
Anas kayani
Anas kayani - avatar
7 Answers
+ 4
#include <iostream> using namespace std; int main() { int i; string arr[3]; //line 1 cin>>i; //line 2 for(i=0;i<3;i++) // line 3 cin>>arr[i]; //line 4 cout<<arr[i]; //line 5 return 0; } Line 1- no need for size specification when using string data type in c++. Line 2- input arr, not i Line 3 - when using string data type, you can get the size of the string as arr.size() in c++. Line 4 & 5 - these should be inside {} as they are inside for loop. So the final code #include <iostream> using namespace std; int main() { int i; string arr; cin>>arr; for(i=0;i<arr.size();i++) { cin>>arr[i]; cout<<arr[i]; } return 0; }
5th Dec 2020, 3:24 PM
Charitra
Charitra - avatar
+ 3
Your cin >> i is useless because after cin you assign 0 to it in for loop. Also you didn't use { } in for loop. When there are 2 or more statements in the loop. Use for(...) { /*code*/ }
5th Dec 2020, 3:23 PM
你知道規則,我也是
你知道規則,我也是 - avatar
+ 1
Thanks alot sandeep .this code is very helpful
6th Dec 2020, 8:13 AM
Anas kayani
Anas kayani - avatar
0
I want to input three subjects marks
5th Dec 2020, 3:24 PM
Anas kayani
Anas kayani - avatar
0
Using array
5th Dec 2020, 3:24 PM
Anas kayani
Anas kayani - avatar
0
Anas kayani if you want to store three subjects. You don't need to let user input i. Take cin >> i out. And you need { } after for loop to make sure the output is also in for loopm
5th Dec 2020, 3:28 PM
你知道規則,我也是
你知道規則,我也是 - avatar
0
Ok
5th Dec 2020, 3:29 PM
Anas kayani
Anas kayani - avatar