+ 1

Can someone help me with this code.

Like I want a user to input 10 integers(marks) in the same line and then set a pass mark of her choice. The output should be the count of the marks that are above or equal to the pass mark https://code.sololearn.com/cYA77yGghkNr/?ref=app

26th May 2022, 2:51 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
7 Answers
+ 1
array<int,10> saved = {}; // array is not predeined keyword , you may trying vector thrn use vector innplace of array array<int,10> users; cin >> users; //thid only accept single input cin >> pass; for (int i=0; i<users.size(); i++){ saved.push_back(users); for (int x: saved){ if(int x: saved>= pass){ // wrong syntax for comparision... count = count + 1; } } } cout << count << endl; Corrected way are : vector<int,10> saved = {}; //declare vector int marks; for (int i=0; i<10; i++){ cin>>marks; // take a input of int saved.push_back(marks); // add to vector } for (int x: saved){ // read vector if( x >= pass){ // compare x with pass marks count = count + 1; } } Hoping you can reform owl code again.. Hope it helps... edit: add vector header #include <vector> your 2nd of header is invalid. remove it..
26th May 2022, 3:04 PM
Jayakrishna 🇮🇳
+ 1
Set pass value and vector<int> saved(10); declare vector of size 10 with all set to 0. Instead use vector<int> saved{}; int pass = 5; // set pass marks or take input
26th May 2022, 3:52 PM
Jayakrishna 🇮🇳
+ 1
Jayakrishna🇮🇳 thanks it's working perfectly now.
26th May 2022, 4:04 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
26th May 2022, 2:51 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
Jayakrishna🇮🇳 it prints out 20 for ever inputs😔
26th May 2022, 3:39 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
You can check it I edited it
26th May 2022, 3:39 PM
Siyabonga Mbendane
Siyabonga Mbendane - avatar
0
You're welcome... edit: Siyabonga Brian don't take input for pass in loop.. it ask input in each iteration. take before loop.
26th May 2022, 4:09 PM
Jayakrishna 🇮🇳