[try Beta version]
Not logged in

 
stuck in a simple program :( (area)

Dec 18, 2010 at 7:20pm
so i decided to make a program in which u have area given and base/height etc .

so lets say

the sum is
area=11.6
base=?
height=2.9

the ans should be...AREA of triangle = 1upon2*b*h
11.6=1/2*b*2.9
h=11.6/2.9*2 = 8
so i am really confused how to make a program which will do something like this

like i cant declare cin because it wont take decimals ? ?:((

so how can i do it


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# include <iostream>
# include <string>

using namespace std;
int main ()
{
    int a ,b,c;
    string mystr;
    cout <<"area to find breadth or height of a triangle " << endl;
    cout << "enter ur breadth /height " << endl;
getline (cin,mystr); 
cout <<" enter ur area" <<endl;
getline ( cin,mystr);
cout << " the ans is " << ?? ? ? << endl;
scanf ("%d%",&c);
return 0;
}



please tell me what can i put in the question marks ..or what other methods to create such programs
Dec 18, 2010 at 8:07pm
you should see a tutorial of some kind..

anyway. contemplate this:
1
2
3
4
5
6
7
8
9
10
#include <iostream>

int main(){
    float a;
    std::cout << "Enter a number a = ";
    std::cin >> a;
    std::cout << "2a = " << 2*a;
    std::cin.ignore().get();
    return 0;
}
Dec 22, 2010 at 6:48pm
wow didnt understood what u told just then .. wouldnt it just multiply a with 2 ?
Dec 22, 2010 at 7:09pm
it would ask you to enter an integer and then print twice as much.
the point was to show integer input. you seemed not to know how that is done.
Dec 22, 2010 at 9:19pm
point being, cin does take actually take fractioned numbers :) It doesn't take whole sentences (or anything after the space/ enter).

Just use the right variable type :)
Last edited on Dec 22, 2010 at 9:19pm
Dec 23, 2010 at 3:29pm
omg!! .. . lolz my bad ..how did i mis looked ..ok problem solved thanks :)))
Topic archived. No new replies allowed.