#Simple code not running!

86 messages · Page 1 of 1 (latest)

toxic compass
#

This simple code isnt working, it is supposed to take an input of seconds and turn it into hours, minutes, and seconds..... For some reason it doesnt work...

bright matrixBOT
#

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

Screenshots!

Your message appears to contain screenshots but no code. Please send code and error messages in text instead of screenshots if applicable!

toxic compass
#

!howto

bright matrixBOT
#
howto

Retrieve wiki articles (alternatively /wiki)

!howto <query> Retrieve wiki articles (alternatively /wiki)

toxic compass
#
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";
}

worthy cradle
#

there is an error

toxic compass
#

wait what

worthy cradle
#

it's in your screen shot

toxic compass
#

really?

#

I dont see what its trying to say

#

did I do the percent sign wrong or someting?

worthy cradle
toxic compass
#

what is it trying to say?

worthy cradle
#

that time isn't an int

#

there are probably more errors

#

this is a using std namespace error I suspect

toxic compass
#

but I set time to int before

bright matrixBOT
#
Why Is `using namespace std` Considered Bad Practice?

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;
worthy cradle
#

then why does it have a red squiggle under it

toxic compass
#

wdym? When you set

#

int time

#

does it not work?

worthy cradle
#

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

toxic compass
#

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

worthy cradle
#

programming in what word 2008?

#

I dunno man

#

professor is sus

toxic compass
#

I know 😭

#

but idk what t odo

worthy cradle
toxic compass
#

because theoretically my code should work

worthy cradle
#

you need to read more carefully

toxic compass
#

oh?

worthy cradle
#

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

toxic compass
#

I just checked again, and the code seems to be exactly the same apart from the output

toxic compass
#

i mean the cout >> ...

worthy cradle
#

I look at two screen shots

#

and they are quite different

#

dozens of differences

worthy cradle
#

why do you expect it to output the same thing?

toxic compass
#

!solved

bright matrixBOT
#

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

low bridge
#

writing code in word or notepad

ember idol
#

even if you didnt, just dont use it

toxic compass
#

Oh ok

unique sedge
#

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

unique sedge
# toxic compass

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.

latent quiver
ember idol
#

Don't use it bruh it's a bad practice always use
std::
For IO functions.
std:: has nothing to do with IO functions

unique sedge
#

simply would get an error

ember idol
#
#include <iostream>
using std::cout;

int main(){
  cout << "Hello world!";
}
half crescentBOT
#
Program Output
Hello world!
ember idol
ember idol
toxic compass
#

Im just doing what my professor teaches

unique sedge