Hey Sup Forums, I really don't know who else I can turn to

Hey Sup Forums, I really don't know who else I can turn to

I have an assignment in my C++ class and it seems fairly simple at first, but the second part of it got me a bit lost (pic very related);

How would one go about letting a user put in a conversion factor and then build a table out of first 10 values with the conversion factor provided?

Thank you for your input

Other urls found in this thread:

stackoverflow.com/questions/2872543/printf-vs-cout-in-c
math.stackexchange.com/questions/1506617/perfect-matching-in-n-dimensional-hypercube
twitter.com/NSFWRedditImage

OP here, this is what I got so far, it's my first C++ thing I ever did so it's probably retarded

Consider switching majors

Just cin a float for conversion factor then multiply 1-10 by the factor and print it out as a nice pretty table.

A for loop will let you do this in 2 lines of code.

Maybe programming isn't for you?

I know it's not, but I need it for my logistics major, I just want to pass it and forget it

So it would be something like

double x;
cin >> x;
cout

Fuck off and pay a classmate to do your homework, you dumb MBA-shitter.

pretty much. Most of the programming is pretty printing. Its just multiplication.

There are better ways to do it, but even you should be able to hack out a solution in at most 10-15 minutes

What the fuck, OP.
The instructions clearly state the expected output, and you immediately start typing bullshit and adding typos. Convertion? wtf is that.
Please go to office hours.
You are not going to pass this class.

"... into the destination currency, using conversion factor provided by the user", and thanks for pointing out the typo, that happens to me some time since English isn't my first language пeтyшoк oбocцaный

jesus christ op
this is pre programming knowledge
literal bottom of the barrel shit

EXPECTED OUTPUT:
Options:\n
1: USD -> EUR\n
2: EUR -> USD\n
\n
Please select an option:

YOUR OUTPUT:
Hello,\n
\n
Press 1+Enter to do a dollars to euros conversion, Press 2+Enter to do a euros to dollars conversion :

FUCKING CAPSLOCK IM SO MAD
If i was grading this I would give you a 0 even if it worked perfectly.
How are graders supposed to diff output when no1 pays attention to guidelines.

I didn't know how to make it the right way lol

Protip: use boolean for the options, as you dont need more than 2 options

wew lad you mad?

It's literally just type what you see them asking you to type. Make it look like theirs. Even Dudley from the Royal Tenanbaums could do that one. Please fix the output, and I'll be glad to help with the rest of the logic.

cin.get(x)
a = 0
For (i = 1; i < 11; i++)
a = i*x+ a
cout

is this better?

that looks like it has potential in it, looking into it now

Delete the first two cout lines.
Also using namespace is bad practice, but that's okay in this kind of program.
Once you get the conversion rate from standard input, print the EUR USD table header and then all you have is a for loop to write.
for (int i = 1; i

Im a dumbass friend, forgot define the int.

cin.Get(x)
a = 0
For (int i = 1; i < 11; i++)
{
a = i * x + a;
cout

this is super wrong

super wrong v2.0

Where in the program does it ask you to say hello?

hilariously incorrect I LOVE THIS THREAD

Like i said breh. No clue how c++ works, whats wrong about this

every time you go through the loop, you're adding a to itself and then also adding the conversion rate multiplied by i.
All the question asks is to print i*conversion rate in increasing order from 1 to 10.

Cin and cout are fucking retarded. They are objects that use bit shift operator to print or read text. Why the fuck? What was wrong with printf function?

float factor;
cin >> factor;
int i, value;
cout

agree. love me some printf.

Really? I made it so that it output a every time it added i * x to a
So i figured it would do

i * x + a = 1.4
Then on the next pass its -
Okay yeah i see where the mistake is. Thanks user i'm an idiot

well, it must greet the user, am I wrong?
thank you, gonna be testing it now
no problem bud, any input is nice lol

I don't like printf.
Overloaded operators 4 lyfe.

No, really, printf has the look and feel of deprecation compared to cout.

Thank you, I'm starting to get something out of that, but for some reason it abruptly disappears

>yfw printf is slower than std::cout

You have no idea what you're talking about.

C style variable arguments are great and consistent.

Stream operator overloading with the bitwise shift operator is the epitome of shit.

lol it isn't slower. You're funny though.
stackoverflow.com/questions/2872543/printf-vs-cout-in-c

Somewhat valid, cout adds inheritibility and all that shit listed on stackoverflow.
Not that stack overflow isn't often wrong.

Hello, so I am hearing you are having troubles with your HW assignment? No problem friend. I will assist you with your problem.
int euro=0;
int usd=0;
int xRate=0;
int choice=0;
int obama=1;
cin>>choice;
cin>>xRate;


while(choice!=0&&obama){
if(obama)
{cout

Guessing you're using an IDE like VS.
Try just running the binary from the cmd.
Or add 'getch();' before the closing brace.

lol'd.
Also is there some tag I don't know about? It looks like there is.... shit

thank you very much for you input friend, your warmth will caress me in the night

>using namespace std
kek

for (int i = 1; i

already mentioned that
not that he cares or even a grader would care

he's not a CS major
fuck, am I the only one in this thread that reads other posts?

Okay I will be the autist here. Run this. Use std::setw to format the table

#include
#include

typedef enum {
UsdToEur
, EurToUsd
} ConversionFactor;

int main(int argc, char** argv)
{
ConversionFactor eOpt;
float fFactor;
std::string sFrom, sTo;

std::cout fFactor;

std::cout

Chances are you are right but I still prefer cout over printf.
cout just seems easier and more flexible than using printf.
Definitely sounds like VS. When I was taking courses, I resolved to use system("pause") because it was the quickest answer google could give me. It's a bad practice and I've long since stopped.
A better way to do stop VS from closing the console window without constantly adding a line to your programs just for that is to use the feature "Run without debugging" , or, ctrl+f5 (you can add the button to the window frame, too).

+1 for casting to float
-10 for unsafe casting

i'm not a CS major either

this is basic math

Lol

CS is for people who are to dumb for math and too dumb for science

It's what they're teaching students to do these days. Sure enough, it's confusing as fuck to a complete novice when they go online to seek help and see std:: prefixing a bunch of things that their textbook would print plainly, ie cout and vector.

Nope, CS major here. Minor in math. Always did better in math courses. Could have switched to double major but I prefer CS courses for their focus on application.

WHY are you using VS?
WHY are you coding in Windows?

We did it Reddit!

...

yeah, especially with c/c++. At least use cygwin, super easy to install just make sure u check the boxes for gcc/g++ and vi/vim (if available).

Press Windows key + r
Type cmd
You should see "C:\Users\yourusername>" with a blinking _
Type cd (meaning change directory) (DON'T PRESS ENTER)
Now, the goal is to change to the directory with your Visual Studio project
By default, this is C:\Users\you\Documents\Visual Studio 15\Projects\projectname
You can type part of the directory name and press Tab to complete it
For example, you start out with C:\Users\you
type cd Doc and press Tab, and it will automatically complete to look like cd Documents
You can press \ (backslash) and then type another folder name to complete the name of a folder inside Documents
For example, you have cd Documents\Vis and you press Tab, and it changes to cd "Documents\Visual Studio 15" (the quotations are necessary because the directory name has a space)
Then delete the last quotation mark, press \ (backslash), start typing the name of the project, press Tab
Make it so it looks like cd "Documents\Visual Studio 15\Projects\projectname\Debug" (15 may be a different number)
After that press Enter.
Not it should say C:\Users\you\Documents\Visual Studio 15\Projects\projectname\Debug>
Start typing the name of the project and press Tab. It should autocomplete to something like projectname.exe
Press Enter, and you should see the output of your program.

huh?

>cygwin
Good G*d, no!

Should've majored in tripal integrals instead

Hey, I hate emulating too, but definitely better than whatever windows IDEs are out there.

C style casting is perfectly valid if the types are integral.
You can replace it with static_cast if you're that anal about it.

This is why people learning to code shouldn't use IDEs fyi

>tripal integrals
Showing results for triple integrals instead
Search instead for tripal integrals?
God I hope you don't have a college degree.

Now that OP's homework has been done by autists can we talk about 17-dimensional hypercubes?

PLEEEEEASE?

No. Windows has a great ide for Windows development. Cygwin is a bandaid for lazy people and you are better off going mingw or just full linux instead

>my little shitposter cant be this new

When I was doing HW assignments, I would always favor using double over float. Something about decimal number precision iirc. So, basically anything that had me print or use a number with several decimal places was full of double declarations instead of float. How dumb was that?

I'll take your word for it.
I really don't like cygwin either but it's closer to Linux and you don't have to fuck around with IDEs and waste your brain on autocomplete.

math.stackexchange.com/questions/1506617/perfect-matching-in-n-dimensional-hypercube
Let's talk, homie.

holy fuck this is hard mode.
just use "start without debugging" / ctrl+f5

Float is expensive. At that level final decimal precision can probably be handled with doubles

If you want something "closer to Linux" I emplore you to use mingw then.

Okay, what?
Am I the only one who thinks this guy might have brain issues, or am I a complete idiot?
>inb4 both
Doubles are double precision (64-bit) whereas floats are 32 bit single precision.
How is float more expensive than double?

>this is hard mode.
Literally all he is doing is changing directory on a command line and then running a program.
That is the most basic you could possibly do.

Do winplebs really not know how to use an operating system?

No, I'm a Linux fag, definitely only use windows for the occasional game, but it's been months since I booted into win7. Not looking to do any development on windows.

literally all he is doing is expending a lot more energy with the manual labor of typing and clicking and typing and clicking when even litterally adding one dumbfuck line to every program would be easier literally

You mean these?

If I'm not misunderstood float uses IEEE standard, with mantessas and shit, while double is just a wide integer basically

Just scanning his long ass post made it seem like a lot of shit just to keep it from exiting immediately. I still haven't read that whole thing. Shoulda put a tl;dr at the end.

See, this is why I thought using doubles errywhere was fine but then I read that floats are 4 bytes whereas doubles are 8, thus, potentially wasteful (even if it was for the simple shit I was doing).

;-)

Single precision (float) gives you 23 bits of significand, 8 bits of exponent, and 1 sign bit.

Double precision (double) gives you 52 bits of significand, 11 bits of exponent, and 1 sign bit.

Both use encoding and need to be decoded.
Pretty sure I'm correct in saying that doubles are heavier than floats in both space and decoding complexity.

>calling people out while unironically referring to programming as coding

Good call, but the perf difference is more from calculation time than mem size

But I'm liking this discussion and would love to be proven wrong.

see
amiwrong?

Doubles are NOT heavier than floats. What exactly do you think a FLOP is?

Enlighten me

floating point operation.
Where's your argument exactly?
Would still love if someone would prove me wrong. Keyword: prove.

i made the code to the 2 option.
i'm beginner too, notations are in portuguese
int choice;
cin >> choice;
if (choice==2){
cout > x;
int i;//i=moeda no caso 1 vai ser o dolar
for (i=1;i

hey OP i did your homework

I'll post the solution if you post a timestamped picture of yourself holding a sign saying "MAKI MAKI GIMMIE DAT FAKI"

People use FLOPS because a flop is the most expensive operation, making it a more meaningful measure of power.

Doubles are double-precision floats.
AKA they are just bigger floats (4 bytes larger, so obviously in terms of space they are heavier)

I'm beginning to think this thread is 99% trolls.

hahhaaaa

What year are you?
Take a fucking proof class please

Not an argument

I've graduated. Tell me what I said wrong...

senpai pls

Okay, here's what your mistake was:
While doubles should be the default in modern programs, floats are less resource intensive. Doubles are literally double precision floats. WTF

fucking god it said the image was attached but it wasn't

>People use FLOPS because a flop is the most expensive operation, making it a more meaningful measure of power.
People use flops because the vast majority of supercomputers are interested in floating point operations for their calculations.

Haskell

{-# LANGUAGE UnicodeSyntax #-}
import Control.Monad (forM_, foldM_)
import Numeric (showFFloat)

data Currency = USD | EUR
deriving (Eq, Show, Read)

main ∷ IO ()
main = do
let to = (,)
let conversions = [USD `to` EUR,
EUR `to` USD]
let printConv (a,b) = show a ++ " -> " ++ show b
putStrLn "Options:"
foldM_ (\i x → do
putStrLn $ show i ++ ": " ++ printConv x
return (i + 1)
) 1 conversions

putStr "\nPlease select an option: "
option ← read getLine ∷ IO Int
let choice@(from,to) = conversions !! (option - 1)

putStr $ "\nPlease insert the conversion factor (" ++ printConv choice ++ "): "
factor ← read getLine ∷ IO Double

putStrLn $ concat [ "\n", show from, "\t", show to ]
putStrLn $ replicate 16 '-'

[1..10] `forM_` \i →
putStrLn $ show i ++ "\t" ++ showFFloat (Just 1) (i * factor) ""


as close to pic as I could get

finally someone comes to my aid
thank you sir