Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Code:
cin >> CAD;

CAD = (0.98 * USD);

You get CAD then overwrite it with the following calc.
Anything times zero, which is what you set USD too, is equal to zero.

yeah i figured it was something like that i just dont know how to alter it
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Code:
CAD = (0.98 * USD);

Will take the contents of USD, multiply it by 0.98, and store it in CAD. Is that what you want?

Yeah I think so.. I just have to write a code tht converts CAD to USD..which would be the opposite of what you just said I think.
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Yes, so in code you'd want to take the number of CAD multiply by 0.98 and store the result in a new variable. How would you write that in code?

ugh i dont know. this class is going to be the death of me.

0.98 * CAD = USD? :confused:
 

lloyddean

macrumors 65816
May 10, 2009
1,047
19
Des Moines, WA
Code:
double USD = 0, CAD = 0;
cin >> CAD;
CAD = (0.98 * USD);

Again - you ask the user to give a value for CAD.

Then you assign the result back into CAD with:

CAD = (.98 * USD)

... or ...

CAD = (.98 * 0)

... resulting in ...

CAD = 0

A little Algerbra should allow you to figure this out.
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Ok, you have the math equation written correctly, but how does the assignment operator (=) work in C? Can you store the number 5 in the variable x by writing

Code:
5 = x;

?

so that would be x = 5; am i right?

----------

Code:
double USD = 0, CAD = 0;
cin >> CAD;
CAD = (0.98 * USD);

Again - you ask the user to give a value for CAD.

Then you assign the result back into CAD with:

CAD = (.98 * USD)

... or ...

CAD = (.98 * 0)

... resulting in ...

CAD = 0

A little Algerbra should allow you to figure this out.

REason number 1 why I took a programming course as my math elective: i suck at algebra.

can i set it so that USD > 0? is it possible to just replace the equals sign with >? SO CONFUSING
 

mobilehaathi

macrumors G3
Aug 19, 2008
9,368
6,352
The Anthropocene
so that would be x = 5; am i right?

Yes, so you assign a value to a variable by putting the variable on the left and the value on the right.

Now you've read in the number of canadian dollars and stored it in CAD. You know that to convert to us dollars you need to multiply CAD by 0.98. So you want to take that result and store it in your USD variable.

So, convert my words into code. You know how to do it!
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Yes, so you assign a value to a variable by putting the variable on the left and the value on the right.

Now you've read in the number of canadian dollars and stored it in CAD. You know that to convert to us dollars you need to multiply CAD by 0.98. So you want to take that result and store it in your USD variable.

So, convert my words into code. You know how to do it!

unfortunately i do not. :( my life sucks

----------

sweet baby jesus i think i got it.

----------

Code:
#include <iostream> 
using namespace std;

#include <iomanip> 
using std::setprecision;

int main ()
{ 
	double USD, CAD;

	cout << setprecision (2) << fixed; 
	
	cout << "Enter the amount of CAD: ";
	cin >> CAD;

	while (USD != 0)
	CAD = 0.98 * USD; 
	USD = 0.98 *CAD;

	cout << "$" << CAD << " CAD is equal to $" << USD << " USD" << endl;
		
	return 0;

}
 

mobilehaathi

macrumors G3
Aug 19, 2008
9,368
6,352
The Anthropocene
unfortunately i do not. :( my life sucks

Yes you do. You have written

Code:
CAD = (0.98 * USD);

which multiplies the value of USD by 0.98 and stores it in CAD. You want to multiple the value of CAD by 0.98 and store it in USD. How do you do that?

----------

[/COLOR]sweet baby jesus i think i got it.

----------

Code:
#include <iostream> 
using namespace std;

#include <iomanip> 
using std::setprecision;

int main ()
{ 
	double USD, CAD;

	cout << setprecision (2) << fixed; 
	
	cout << "Enter the amount of CAD: ";
	cin >> CAD;

	[B]while (USD != 0)
	CAD = 0.98 * USD; [/B]
	USD = 0.98 *CAD;

	cout << "$" << CAD << " CAD is equal to $" << USD << " USD" << endl;
		
	return 0;

}

You don't need what I've bolded.
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Yes you do. You have written

Code:
CAD = (0.98 * USD);

which multiplies the value of USD by 0.98 and stores it in CAD. You want to multiple the value of CAD by 0.98 and store it in USD. How do you do that?

----------



You don't need what I've bolded.


aw yay! thank you so much for your help i cant believe i was being that dumb.
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
You'll get the hang of it.;)

its literally like learning a whole new language!
im going to ask you a quick question while youre here..
the problem says "Write a C++ program to display the following sum:
4 + 8 + 12 + 16 + 20 + 24 +...+ 404

i dont understand how to get it to output as that, this is as close as i came:

Code:
#include <iostream>
using namespace std;
int main ()
{
	int x = 4;
	while ( x <=404 )
	{
		cout << x << endl;
		x += 4;
	}
	return 0;
}

which obviously just displays every 4th number up to 404

----------

its literally like learning a whole new language!
im going to ask you a quick question while youre here..
the problem says "Write a C++ program to display the following sum:
4 + 8 + 12 + 16 + 20 + 24 +...+ 404

i dont understand how to get it to output as that, this is as close as i came:

Code:
#include <iostream>
using namespace std;
int main ()
{
	int x = 4;
	while ( x <=404 )
	{
		cout << x << endl;
		x += 4;
	}
	return 0;
}

which obviously just displays every 4th number up to 404

ACtually i think this works..
Code:
#include <iostream>
using namespace std;
int main()
{	
	int sum = 0;
	for (int x = 4; x<=404; x+=4)
	sum += x;

cout << "Sum equals " << sum << endl;

return 0;
}
yay me?
 

mobilehaathi

macrumors G3
Aug 19, 2008
9,368
6,352
The Anthropocene
its literally like learning a whole new language!
im going to ask you a quick question while youre here..
the problem says "Write a C++ program to display the following sum:
4 + 8 + 12 + 16 + 20 + 24 +...+ 404

i dont understand how to get it to output as that, this is as close as i came:

Code:
#include <iostream>
using namespace std;
int main ()
{
	int x = 4;
	while ( x <=404 )
	{
		cout << x << endl;
		x += 4;
	}
	return 0;
}

which obviously just displays every 4th number up to 404

----------



ACtually i think this works..
Code:
#include <iostream>
using namespace std;
int main()
{	
	int sum = 0;
	for (int x = 4; x<=404; x+=4)
	sum += x;

cout << "Sum equals " << sum << endl;

return 0;
}
yay me?

See, you're getting the hang of it!
 

chrono1081

macrumors G3
Jan 26, 2008
8,446
4,146
Isla Nublar
Programming takes practice and dedication, but it'll come with time. Who knows maybe you'll end up really liking it and become a computer programmer ;)
 

oxshannon

macrumors regular
Original poster
Jan 5, 2012
113
0
Programming takes practice and dedication, but it'll come with time. Who knows maybe you'll end up really liking it and become a computer programmer ;)
mmm im unsure about that, but you never know! haha i just like the moment of glory when i run something and theres 0 errors and it actually does what i want
 

danwilliams

macrumors member
Sep 15, 2008
46
0
mmm im unsure about that, but you never know! haha i just like the moment of glory when i run something and theres 0 errors and it actually does what i want

Having been a software developer for the last 20 years, I can safely say that you have just done one of the hardest things in programming. You completed your first few assignments. And (bonus points) you got a rush at that "aha" moment of when it compiled and worked.

One of the comments by you earlier was that you were "not good at algebra". Just realize this is a justification for not trying or giving up. You have just proven to yourself (and us) that you DID NOT GIVE UP. All of us on this thread can attest that we have been in the same exact position you were just in earlier in our careers. We too did not give up. And we too came up with justifications to give up. "It's too hard." "I suck at writing." "I hate math." "I am an artist." "I am a lover not a fighter." "I hate it." etc...

Hang in there. With time and the effort you just showed, it will get easier.
 

chrono1081

macrumors G3
Jan 26, 2008
8,446
4,146
Isla Nublar
I remember when I was learning my biggest issue was with classes. I was so confused by them! The syntax was weird, I didn't get what purpose they served, and the example I was given was awful.

After some digging I found a tutorial on them that didn't try and impress the reader by showing all kinds of bells and whistles but instead showed a basic class, then it clicked and now I can't imagine never creating classes.

You will run in to many scenarios like that in programming but with a bit of digging you'll find examples that work for you and whatever you are trying to understand will click and you'll be on your way to the next concept.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.