Anonymous
Ok
Mohammed
can i control the number of array in input?? for example if said number_of_student[30] cin»number_of_student so that if i choosed 3 the program ask me to enter the score for each student n print the highest score i did it with while loop but i can't get the highest score correctly see the code #include <iostream> using namespace std; int main() { int NMBR_OF_STUDENTS = 0; double counter = 0.0; double grade = 0.0; double HIGH_GRADE = 0.0; cout<< "How many students do you need to enter grades for? " ; cin>>NMBR_OF_STUDENTS; cout<<endl; while (counter < NMBR_OF_STUDENTS) { cout<< "Enter grade " << counter + 1; cout<< " ===> "; cin>> grade; //need to calculate for highest grade but no clue counter ++; } while (HIGH_GRADE >= grade); //told to use while statement to find highest grade cout<< grade << " is the highest grade." <<endl; return (0); }
Mat
what does that mean?
Format your code like this
Dima
put three ` around
Mohammed
You can use if else or ternary operator
yeah i know but how can i say it ma mind gonna blow now
Kumar Vipin
yeah i know but how can i say it ma mind gonna blow now
Ok take 1 student mark out of loop and store that in high_grade
Mohammed
#include <iostream> using namespace std; int main() { int NMBR_OF_STUDENTS = 0; double counter = 0.0; double grade = 0.0; double HIGH_GRADE = 0.0; cout<< "How many students do you need to enter grades for? " ; cin>>NMBR_OF_STUDENTS; cout<<endl; while (counter < NMBR_OF_STUDENTS) { cout<< "Enter grade " << counter + 1; cout<< " ===> "; cin>> grade; //need to calculate for highest grade but no clue counter ++; } while (HIGH_GRADE >= grade); //told to use while statement to find highest grade cout<< grade << " is the highest grade." <<endl; return (0); }
Dima
Oh you made it, success
Dima
but there’s no array
Kumar Vipin
Oh you made it, success
Can i type code for his understanding 🤔
Dima
why not
Mohammed
but there’s no array
yeah cuz i couldn't do it with arrays n the lecturer wants it in array that's why i asked ...i could do it almost using while loop but whenever i use arrays i messup everything
Kumar Vipin
yeah i know but how can i say it ma mind gonna blow now
#include <iostream> using namespace std; int main() { int NMBR_OF_STUDENTS = 0; double counter = 0.0; double grade = 0.0; double HIGH_GRADE = 0.0; cout<< "How many students do you need to enter grades for? " ; cin>>NMBR_OF_STUDENTS; cout<<endl; cout<< "Enter grade \n"; Cin >> HIGH_GRADE; while (counter < NMBR_OF_STUDENTSSTUDENTS-1) { cout<< "Enter grade " << counter + 1; cout<< " ===> "; cin>> grade; //need to calculate for highest grade but no clue // here you go If ( HIGH_GRADE < grade) HIGH_GRADE = grade; counter ++; } return (0); } Cout <<" highest grade is " << HIGH_GRADE; It look something like this I can't write code in mobile 😁
Dima
don’t call variables like that
Dima
klimi
const should be uppercase
Dima
no
Dima
well yes and no
Dima
but in this case no
klimi
like when you define pi
klimi
it can be upper
Kumar Vipin
yeah i know but how can i say it ma mind gonna blow now
First student mark is been taken as highest grade and then we take input for number of students - 1 and then we compare if any input is greater then we store that as highest grade And in last we print that
Kumar Vipin
don’t call variables like that
Sorry i am on mobile so can't type fast so just edit his code a little bit 😔
Mohammed
First student mark is been taken as highest grade and then we take input for number of students - 1 and then we compare if any input is greater then we store that as highest grade And in last we print that
i see.....great thanks for ya i'll try to work it out with using arrays...i can use the same way right? it's not gonna differ much
Kumar Vipin
Assume index 0 as maximum and start comparing from 1 to end
Kumar Vipin
Thanks a lot...
Not a problem 😁
Kumar Vipin
Kumar Vipin
How come it hase an address when it's created in the next stage? No I haven't, I think that's for Cpp.
I think that pointer has a garbage addresses when it created. Correct me if I an wrong.
🐰🐾 سمیه
That makes sense
olli
I just know exception was removed from 17
No, exceptions are still part of C++
Kumar Vipin
That makes sense
I haven't try it yet but I will try it in morning and tall you ☺ It's midnight here so have to go Till then Enjoy coding.
Kumar Vipin
How can you check that. Gn
Just by printing a pointer value In my compiler.
Kumar Vipin
Like Int *p; Printf("%d", *p) ;
🐰🐾 سمیه
Ok. 👌
Kumar Vipin
Like Int *p; Printf("%d", *p) ;
If it print something that's the garbage value
Kumar Vipin
Ok. 👌
Ok see you soon👀👈⏰
Ибраги́м
That makes sense
U mean "no sense"
🐰🐾 سمیه
Ибраги́м
1. Garbage? We don't use that language in here. Either say Uninitialised or undefined behaviour depending on the context 2. Using value Uninitialised object is an undefined behaviour, the address is well-defined the moment u bring it into scope.
Anonymous
https://pastebin.com/hu3wRFw0 how would i use methods to better pass the acc ref
Dima
I know this is unrelated, but never use using namespace std;
Anonymous
why
Anonymous
clean up the code, make it more oop
Dima
why did you create separate method and passing the refs
Dima
move these methods to Account
Anonymous
yes
Dima
e.g. class Account { public: void login(); public: int amount = 1000, loginTries = 4, numInput = NULL; string name; };
Anonymous
thanks
Anonymous
https://pastebin.com/hu3wRFw0 i understand the first half but not relative to a specific object
Dima
you need to instantiate Account first
Dima
or make methods static, but this is worthless in current case
Dima
Account acc(whatever your constructor params); acc.login();
Anonymous
thanks, ive been watching cpp videos but they dont help as much as practicing
Ashish
yess
Anonymous
Helo
Anonymous
Developer of c++ ?
Anonymous
Hi
Aloknath
Hlw Charles
Aloknath
Akash Chandra
Sorry
Akash Chandra
Mistake
🐰🐾 سمیه
Hi In C, If we declare a floating-point variable, accordingly its pointer should be a pointer to float. My question is, is it because, for example, the address of a float object is a floating-point number, so it must necessarily be stored in a float object?