#Simple code not running!
86 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
@toxic compass
Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!
!howto
Retrieve wiki articles (alternatively /wiki)
!howto <query> Retrieve wiki articles (alternatively /wiki)
using namespace std;
int time, hours, minutes, seconds, allminutes;
int main() {
cout << "Please give me a time in seconds";
cin >> time;
allminutes = time/60;
hours = allminutes/60;
minutes = allminutes % 60;
seconds = time % 60;
cout << "Hours: " << hours << "Minutes: " << minutes << "Seconds";
}
there is an error
wait what
it's in your screen shot
really?
I dont see what its trying to say
did I do the percent sign wrong or someting?
what is it trying to say?
that time isn't an int
there are probably more errors
this is a using std namespace error I suspect
but I set time to int before
using namespace std will import all the symbols from std into the enclosing namespace. This can easily lead to name collisions, as the standard library is filled with common names: get, count, map, array, etc.
A key concern with using namespace std; is not what is imported now but rather what may suddenly be imported in the future.
While using namespace std; is alright for tiny projects, it is important to move away from it as soon as possible. Consider less intrusive alternatives:
// OK: *only* import std::vector
using std::vector;
// OK: namespace alias
namespace chr = std::chrono;
chr::duration x;
then why does it have a red squiggle under it
I dunno, what's the red squiggle say?
I'm not psychic, I don't have access to your environment
but yes
every single compiler does not like that
ohhh
I changed it to t
and it worked
but it didnt
ong
how is it giving the wrong output
Its the exact code my professor used
almost
also, it's not
because theoretically my code should work
you need to read more carefully
oh?
programming is about being methodical and detail oriented
the red squiggles mean things
single character differences can change everything
but in no way did you copy the code exactly
I just checked again, and the code seems to be exactly the same apart from the output
I dunno man
i mean the cout >> ...
well I mean yea, that section is entirely different
why do you expect it to output the same thing?
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
by using namespace std you probably made time ambiguos because there is std::time iirc
even if you didnt, just dont use it
Oh ok
try to save your file
if you are using a code runner Extensions must go to the settings and check the mark "whether to autosave file"
and can you paste the code again
where is return 0; , And why you using sm shortcuts Like trying to fit all the expected outputs in one line lol ....And initialisation of variables should be done separately...I personally do separate the output variable and the variable that contain some operating to be done 👍🏻
and this using namespace std; Don't use it bruh it's a bad practice always use std:: For IO functions.
doesn't the main function implicitly returns 0 ?
it does
Don't use it bruh it's a bad practice always use
std::
For IO functions.
std::has nothing to do with IO functions
you cannot use cout and cin without typing using namespace std;
simply would get an error
oh yes u can
#include <iostream>
using std::cout;
int main(){
cout << "Hello world!";
}
;compile
Hello world!
and that still doesnt mean that using namespace std has anything to do with io
and this is something that you could do without polluting the global namespace
yall confusing me
Im just doing what my professor teaches
Ooh sh!t this is something new what the heck wow 😲