declaring problems

I have 2 variables c and 103.5 so now I want to assign 103.5 to c so when people write c It out puts as 103.5? Please help
Is this what you're looking for?
http://cplusplus.com/doc/tutorial/variables/
I think it should work thx.
closed account (zb0S216C)
kingviser wrote:
I have 2 variables c and 103.5 so now I want to assign 103.5 to c so when people write c It out puts as 103.5?

Assuming that c is of type double, 103.5 will not truncate when assigning it. However, assigning a floating-point numerical value to an int, short, or long will cause the value to truncate, reducing the value to 103.

Wazzak
Last edited on
wat abt double?
closed account (zb0S216C)
kingviser wrote:
wat abt double?

What about it?

Wazzak
Ok now the next thing is, how can i enter like 2 values in the same line means, like if i want the use r to enter c than d in the same line so like how do i write a program for that>
Could you please rephrase your sentence into something grammatically correct? :/
I can't understand what you're asking.
closed account (S6k9GNh0)
Its very similar to basic algebraic math.

x = 4;
y = x * x;

The only difference is that y does not change if x changes.

y = x * x; // y is 16
x = 5; //y still equals 16
y = x*x; // y is now 25

If you understand this, programming becomes much easier. The same thing applies to classes, etc. however different rules apply to different things. This is just the basic concept of it.
Last edited on
My bad so this is the problem, ok so I have to ask user to enter C and D, but in one line. so The program outptus please enter C and D, and the user will enter c and D but int he same line.

If you didn't get ^. You know how the user normally enter one variable at a time in programming like either the value or name. But this time the user has to enter 2 at once.
closed account (S6k9GNh0)
You can use getline() which you can use to fetch a line from the cin stream. You'll have to parse it yourself or you can use the delimiter if I'm not mistaken.
Last edited on
no not string here i tried to write the program but it is wrong, but should give you the idea, what i want.

// Menu Chooser
// Demonstrates the switch statement

#include <iostream>
#include <string>
#include<stdlib.h>
#include<windows.h>
using namespace std;

int main()
{
double C=0.0;
string name="";
char choice=' ';
int count=0;



do
{



cout << "WElCOME TO THE song program"<<endl;
cout << "A - SONG 1 "<<endl;
cout << "B - Temporarily Unavilable"<<endl;
cout << "C - Calculate area of Parallelogram"<<endl;



cout << " Your Choice: ";
cin >> choice;

if(choice=='a')
choice='A';
if(choice=='b')
choice='B';
if(choice=='c')
choice='C';
switch (choice)
{
case 'A':
cout << "You picked Son no.1"<<endl;
// input data
do
{

count = count + 1;

cout << "The first key is C, Please enter C"<< endl;
cin >> Beep(103.5,1000);
if (C=="C")
cout<<"You entered the wrong note please try again"<<endl;

}while (C!="C")




system("pause>nul"); //end if
return 0;
}
my bad its not that one this is the one

// Menu Chooser
// Demonstrates the switch statement

#include <iostream>
#include <string>
#include<stdlib.h>
#include<windows.h>
using namespace std;

int main()
{
double C=0.0;
string name="";
char choice=' ';
int count=0;
C=103.5;


do
{



cout << "WElCOME TO THE song program"<<endl;
cout << "A - SONG 1 "<<endl;
cout << "B - Temporarily Unavilable"<<endl;
cout << "C - Calculate area of Parallelogram"<<endl;



cout << " Your Choice: ";
cin >> choice;

if(choice=='a')
choice='A';
if(choice=='b')
choice='B';
if(choice=='c')
choice='C';
switch (choice)
{
case 'A':
cout << "You picked Son no.1"<<endl;
// input data
do
{

count = count + 1;

cout << "The first key is C, Please enter C"<< endl;
cin >> Beep(C,1000);
if (C=="C")
cout<<"You entered the wrong note please try again"<<endl;

}while (C!="C")




system("pause>nul"); //end if
return 0;
}
closed account (zb0S216C)
Maybe scanf( )[1] can help you. In Visual C++ Express 2010, the compiler warns you that scanf( ) is deprecated, and encourages you to use scanf_s( ) instead.

Here's an example that uses scanf( ):

1
2
3
4
5
6
7
8
9
10
11
#include <iostream>

int main( )
{
    int one( 0 ), two( 0 );
    std::scanf( "%d %d", &one, &two );

    std::cout << one << " " << two << std::endl;

    return 0;
}

Beware! scanf( ) isn't type-safe.

References:
[1]http://www.cplusplus.com/reference/clibrary/cstdio/scanf/

Wazzak
Last edited on
Erm, why use scanf() in C++? You're using cout, so I would recommend to just use cin for input.
std::cin >> one >> two;
Topic archived. No new replies allowed.