Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » General Discussions » General Discussion » I Learn Some Basic C++!
Re: I Learn Some Basic C++! [message #392031 is a reply to message #392003] Wed, 24 June 2009 00:51 Go to previous messageGo to previous message
Omar007 is currently offline  Omar007
Messages: 1711
Registered: December 2007
Location: Amsterdam
Karma:
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???


http://tiberiumredux.omarpakker.nl/Old Unused Parts/Plaatjes/PromoteBanner_Hades_small.jpg

[Updated on: Wed, 24 June 2009 00:53]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Your daily commute to work!
Next Topic: Virus
Goto Forum:
  


Current Time: Wed Jan 08 03:44:42 MST 2025

Total time taken to generate the page: 0.01198 seconds