Hello everyone, i'm been practice C++ for a while just a new hobby in technology.
i start with mathematics with numbers and some cout, cin function
in other program like excel i can enter series of number and after that we can:
1. Sum them up
2. Divide them, multiple, list the highest number or smallest or whatever with number since they have some build-in F(x) and its very to use like writing in real life.
in C++ i've been experienced little much more trouble
#include <iostream>
void main()
well after this part i can declare a lot of variables but they are not so practical since the amount of number is fix (eg. 10 is 10 and no more). What i can do if i want to enter as many as i can and after that the mathematics will be later based these input numbers.
#include <iostream>
usingnamespace std;
int main()
{
int num = 0;
double sum = 0;
cout << "enter numbers to be sum: ";
cin >> num;
while(num != 0) //your input will not end unless it is zero
{
sum += num;
cin >> num;
}
cout << "sum of your numbers is: "<< sum << endl;
return 0;
}
i wrote a simple code example here...
i think this code will give you an ideal...
hope it helps...
i can help if thats okay
13) += is a shorter way of saying var1 = var1 + value2
17) what is in "" is the text that is printed and the word sum prints whatever value is currently stored in it
#include <iostream>
usingnamespace std;
int main()
{
int var1 = 5, var2 = 2;
var2 += var1;
//pretend that var2 doesn't have a new value yet
var2 = var2 + var1;
cout<< var2;
#include <iostream>
using namespace std;
int main()
{
int num = 0;
double sum = 0;
cout << "enter numbers to be sum: ";
cin >> num;
while(num != 0) //your input will not end unless it is zero
{
sum += num;
cin >> num;
}
cout << "sum of your numbers is: "<< sum << endl;
system("pause");
return 0;
}
i'm using dev c++, and it seem doesn't have any errors.... you must press space or enter after each number you enter...
// Created by Tuan Minh Pham s0222607 CQU University course COIT0222607 assignment 1
// The program was created in order to caculate series of any numbers and displays these output
// 1. The number of values entered
// 2. Sum of all positive numbers
// 3. Average of first and last numbers
// 4. 70% of smallest positive number
// 5. Largest number entered
// 6. The number of times the largest number is entered
// 7. The two numbers in descending order
#include <iostream>
usingnamespace std;
int main()
{
int num = 0;
int sum = 0;
cout << "enter numbers to be sum: ";
cin >> num;
while(num != 0) //your input will not end unless it is zero
{
sum += num;
cin >> num;
}
cout << "sum of your numbers is: "<< sum << endl;
system("pause");
return 0;
}
This is my full picture now
Still the same........................ after remove line 29
Grax, in the whole picture is my detail of my assignment, need to pull some number and calculate them. Can you give me some other advices for that stuff, going nowhere for past few days and even not pass the first part which is create input
you'll need to include stdlib.h if you're planning on using system("pause") or you can try to get rid of it instead.
I think visual studio actually halts the program automatically at the end if I remember it right, but if it doesn't you need to add the system("pause") to halt program execution before closing so you may view the results.
It's not really a good way of doing things though since it's not portable, but maybe that's what they're teaching you in school. If it is, just do what they expect you to do. :P