Hello everyone,
I am a 15 year old trying to lean programing by myself, I have read some books and online tutorials and I have several questions for you experienced programmers out there. :D
1st question:
what exactly is a(the?) buffer? From my readings it seems to be some sort of intermediary memory that temporarily stores data from and to the console output but I'm not sure.
2nd question
Is there any difference from the
string name
type and the
char string[LENGTH]
?
3rd question
what can the .put() and get() do that << and >> can't?
4th question
Its a work for school I need to make a program that can calculate the result of a second degree equation, here is the code, so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#include<iostream>
#include<cmath>
#include<cstdlib>
using namespace std;
int main(){
float a, b, c, x1, x2, sq;
char sn;
cout << "\t** A formula e' x = (-b +/- Sqrt(b^2 - 4ac))/2a **" << endl;//I'm Portuguese so this is a Portuguese string, it names the base equation
do{
cout << "Inserir 'a' -> ";cin >> a;//asks for a, b and c
cout << "Inserir 'b' -> ";cin >> b;
cout << "Inserir 'c' -> ";cin >> c;
sq = b*b - 4*a*c;//Calculates a chunk of the expression for possible/impossible test
if(sq >= 0){//if it isn't going to give us the sqrt of a negative number...
x1 = ((b*-1) + sqrt(sq))/2*a;//calculate both solutions
x2 = ((b*-1) - sqrt(sq))/2*a;
cout << "\nx = " << x1 << " V x = " << x2 << endl;//give out the solution
}else{//inform the user of the fact that the values he inserted lead to an impossible equation
cout << "\nEquacao Impossivel" << endl;
}
cout << "Deseja inserir outro valor?(S/N): ";cin >> sn;//asks for a second set of values
}while(toupper(sn) == 'S');
system("Pause");
}
|
it gets some right and some wrong, for example:
a-> -1;
b-> 4;
c-> -4;
x = 2 V x = 2 CORRECT!!
a-> 6;
b-> -1;
c-> -1;
x = 18 V x = -12 WRONG!! x = 1/2(0.5) V x = 1/3(0.33333...)
Best Regards and thank you in advance
Deimos