I Learn Some Basic C++! [message #391886] |
Tue, 23 June 2009 01:01 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
Lol this is very very very simple stuff to you guys but after reading on in my c++ book (c++ without fear referred to me by reborn) I made a simple console command prompt that what ever number you type in gets multiply by 100! lol nothing special but im happy im learning something
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double x;
cout << "Enter Number Here To Be Multiplied By 100: ";
cin >> x;
cout << "The Output Is: " << 100 * x;
return 0;
}
|
|
|
|
|
|
|
|
|
|
Re: I Learn Some Basic C++! [message #391966 is a reply to message #391943] |
Tue, 23 June 2009 12:59 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
cnc95fan wrote on Tue, 23 June 2009 09:12 | Now do something where I can enter in a specified amount of numbers, it adds up all those numbers and then gets multiplied by 100
|
I just tryed that, odd enought I can get them to all add up..and even plus another number, but wont multiply correctly for some reason
|
|
|
|
Re: I Learn Some Basic C++! [message #391988 is a reply to message #391886] |
Tue, 23 June 2009 15:48 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
as i said im new and this basic stuff is all i know so far but im just guessing it but here cnc
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double a, b, c, d, e;
cout << "Enter numbers here to be added up (5 is the max) then multiplied by 100 ";
cin >> a;
cout << "Enter second digits: ";
cin >> b;
cout << "Enter third digits: ";
cin >> c;
cout << "Enter fourth digits ";
cin >> d;
cout << "Enter fifth digits: ";
cin >> e;
cout << "The Output Is: " << 100 * a + b + c + d + e;
return 0;
}
|
|
|
|
Re: I Learn Some Basic C++! [message #391996 is a reply to message #391988] |
Tue, 23 June 2009 17:00 |
nopol10
Messages: 1043 Registered: February 2005 Location: Singapore
Karma: 0
|
General (1 Star) |
|
|
SSnipe wrote on Wed, 24 June 2009 06:48 | as i said im new and this basic stuff is all i know so far but im just guessing it but here cnc
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double a, b, c, d, e;
cout << "Enter numbers here to be added up (5 is the max) then multiplied by 100 ";
cin >> a;
cout << "Enter second digits: ";
cin >> b;
cout << "Enter third digits: ";
cin >> c;
cout << "Enter fourth digits ";
cin >> d;
cout << "Enter fifth digits: ";
cin >> e;
cout << "The Output Is: " << 100 * a + b + c + d + e;
return 0;
}
|
Order of operations, what happens here is that a is multiplied by 100 and then added together with b, c, d and e. What you need is to bracket up a+b+c+d+e.
cout << "The Output Is: " << 100 * (a + b + c + d + e);
nopol10=Nopol=nopol(GSA)
|
|
|
|
Re: I Learn Some Basic C++! [message #392003 is a reply to message #391996] |
Tue, 23 June 2009 18:04 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
nopol10 wrote on Tue, 23 June 2009 17:00 |
SSnipe wrote on Wed, 24 June 2009 06:48 | as i said im new and this basic stuff is all i know so far but im just guessing it but here cnc
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double a, b, c, d, e;
cout << "Enter numbers here to be added up (5 is the max) then multiplied by 100 ";
cin >> a;
cout << "Enter second digits: ";
cin >> b;
cout << "Enter third digits: ";
cin >> c;
cout << "Enter fourth digits ";
cin >> d;
cout << "Enter fifth digits: ";
cin >> e;
cout << "The Output Is: " << 100 * a + b + c + d + e;
return 0;
}
|
Order of operations, what happens here is that a is multiplied by 100 and then added together with b, c, d and e. What you need is to bracket up a+b+c+d+e.
cout << "The Output Is: " << 100 * (a + b + c + d + e);
|
OO so simple, so do you always got to put those variables in brackest when theres mroe then one? or always?
|
|
|
Re: I Learn Some Basic C++! [message #392004 is a reply to message #391886] |
Tue, 23 June 2009 18:06 |
raven
Messages: 595 Registered: January 2007 Location: Toronto, Ontario
Karma: 0
|
Colonel |
|
|
It's not just that there's multiple variables. It's that you have to follow the order of operations when doing any mathematical calculation, and brackets are part of said order of operations
BEDMAS - Brackets/Exponents/Division/Multiplication/Addition/Subtraction
-Jelly Administrator
-Exodus Administrator
|
|
|
Re: I Learn Some Basic C++! [message #392008 is a reply to message #392004] |
Tue, 23 June 2009 18:27 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
raven wrote on Tue, 23 June 2009 18:06 | It's not just that there's multiple variables. It's that you have to follow the order of operations when doing any mathematical calculation, and brackets are part of said order of operations
BEDMAS - Brackets/Exponents/Division/Multiplication/Addition/Subtraction
|
ok that makes since thanks for that tip
|
|
|
Re: I Learn Some Basic C++! [message #392031 is a reply to message #392003] |
Wed, 24 June 2009 00:51 |
|
Omar007
Messages: 1711 Registered: December 2007 Location: Amsterdam
Karma: 0
|
General (1 Star) |
|
|
SSnipe wrote on Wed, 24 June 2009 03:04 |
nopol10 wrote on Tue, 23 June 2009 17:00 |
SSnipe wrote on Wed, 24 June 2009 06:48 | as i said im new and this basic stuff is all i know so far but im just guessing it but here cnc
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double a, b, c, d, e;
cout << "Enter numbers here to be added up (5 is the max) then multiplied by 100 ";
cin >> a;
cout << "Enter second digits: ";
cin >> b;
cout << "Enter third digits: ";
cin >> c;
cout << "Enter fourth digits ";
cin >> d;
cout << "Enter fifth digits: ";
cin >> e;
cout << "The Output Is: " << 100 * a + b + c + d + e;
return 0;
}
|
Order of operations, what happens here is that a is multiplied by 100 and then added together with b, c, d and e. What you need is to bracket up a+b+c+d+e.
cout << "The Output Is: " << 100 * (a + b + c + d + e);
|
OO so simple, so do you always got to put those variables in brackest when theres mroe then one? or always?
|
I Would also suggest to make a loop instead of using 5 doubles.
Something like this:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main()
{
double n, t; //n = number filled in, t = total counter
cout << "Please enter 5 numbers seperated by a space";
for(int i=0; i<5; i++) //To increase the number of numbers you can fill in you just have to replace the 5 to another number so you dont have to copy/paste again for every new number
{
cin >> n;
t =+ n;
}
cout << "The output is: " << 100*t;
return 0;
}
EDIT: Havent tested it but wrote it out of my mind but you'll get the idea right???
[Updated on: Wed, 24 June 2009 00:53] Report message to a moderator
|
|
|
Re: I Learn Some Basic C++! [message #392062 is a reply to message #392003] |
Wed, 24 June 2009 10:00 |
|
jnz
Messages: 3396 Registered: July 2006 Location: 30th century
Karma: 0
|
General (3 Stars) |
|
|
SSnipe wrote on Wed, 24 June 2009 02:04 |
nopol10 wrote on Tue, 23 June 2009 17:00 |
SSnipe wrote on Wed, 24 June 2009 06:48 | as i said im new and this basic stuff is all i know so far but im just guessing it but here cnc
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
double a, b, c, d, e;
cout << "Enter numbers here to be added up (5 is the max) then multiplied by 100 ";
cin >> a;
cout << "Enter second digits: ";
cin >> b;
cout << "Enter third digits: ";
cin >> c;
cout << "Enter fourth digits ";
cin >> d;
cout << "Enter fifth digits: ";
cin >> e;
cout << "The Output Is: " << 100 * a + b + c + d + e;
return 0;
}
|
Order of operations, what happens here is that a is multiplied by 100 and then added together with b, c, d and e. What you need is to bracket up a+b+c+d+e.
cout << "The Output Is: " << 100 * (a + b + c + d + e);
|
OO so simple, so do you always got to put those variables in brackest when theres mroe then one? or always?
|
Read up on BODMAS (or BADMAS).
|
|
|
|
Re: I Learn Some Basic C++! [message #392129 is a reply to message #392127] |
Wed, 24 June 2009 18:37 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
YazooGang wrote on Wed, 24 June 2009 18:23 | BUG, BUG, BUG!
Ok, i tried it out and when i need to get the answer, the window closes. I fixed it but fix it your own for your learning. lol
|
Lol, ya I know it runs when you do ctrl+F5 in visual c++ but when you click and run program in folder...closes
|
|
|
Re: I Learn Some Basic C++! [message #392156 is a reply to message #391886] |
Wed, 24 June 2009 21:52 |
dr3w2
Messages: 485 Registered: September 2006 Location: Ottawa,Canada
Karma: 0
|
Commander |
|
|
erm BEDMAS?
Brackets
Exponents
Division
Multiplication
Addition
Subtraction
top to bottom, that's like grade 9 math ...
All languages follow this.. just like your calculator
5*5+2 = 27
5*(5+2) = 35
n00bstories Server Administrator
[Updated on: Wed, 24 June 2009 21:56] Report message to a moderator
|
|
|
Re: I Learn Some Basic C++! [message #392157 is a reply to message #392156] |
Wed, 24 June 2009 22:14 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
andr3w282 wrote on Wed, 24 June 2009 21:52 | erm BEDMAS?
Brackets
Exponents
Division
Multiplication
Addition
Subtraction
top to bottom, that's like grade 9 math ...
All languages follow this.. just like your calculator
5*5+2 = 27
5*(5+2) = 35
|
How would i write thme out in c++? as in how do i knwo which go in abckets and which can i place next to each other?
for example
4 * x (1 + 2) lets pretend thios si teh rite way to write it
how would i know that?a and end up like
1 + 2 (4 * x0 or something..its hard for me to explain
or maybe even
10 * x + 5
[Updated on: Wed, 24 June 2009 22:16] Report message to a moderator
|
|
|
|
Re: I Learn Some Basic C++! [message #392270 is a reply to message #391886] |
Thu, 25 June 2009 14:19 |
_SSnipe_
Messages: 4121 Registered: May 2007 Location: Riverside Southern Califo...
Karma: 0
|
General (4 Stars) |
|
|
What I mean is how do you know there to put the variable, and then the other numbers, and which ones go inside ther brackets
|
|
|