i am noob, i have a problem here.

This is simple problems for you guys but for me, im only first year college im studying this. this is my problem.

My code is this:

#include <iostream>
using namespace std;

void main ()
{
float num1, num2, Fa1, Fa2, Ce1, Ce2;
cout<<"Conversion""\n""\n";
cout<<"1.Fahrenheit to Celsius""\n";
cout<<"2.Celsius to Fahrenheiut""\n""\n";
cout<<"Fahrenheit to Celsius""\n""\n";
cout<<"Enter Fahrenheit:";
cin>>num1;

Fa1=num1 - 32;
Fa2=Fa1 * 5/9;

cout<<"Celsius:";
cout<<Fa2;"\n";

cout<<"Celsius to Fahrenheit""\n""\n";
cout<<"Enter Celsius:";
cin>>num1;

Ce1=num1 * 1.8;
Ce2=Ce1 + 32;

cout<<"Fahrenheit:";
cout<<Ce2;

system("PAUSE");
}



in this is my output.

[IMG]http://i188.photobucket.com/albums/z23/footlongdog/Untitled-7.jpg[/IMG]



My problem is how can i put spaces in the Celsius to Fahrenheit and i also want to put down the "Press any key to continue...."

i use the code "\n" but it did not worked.
how can i solve this problem?
Please use [code] [/code] tags around your source code.

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
28
29
30
31
#include <iostream>
using namespace std;

void main ()
{
    float num1, num2, Fa1, Fa2, Ce1, Ce2;
    cout<<"Conversion\n";
    cout<<"1.Fahrenheit to Celsius\n";
    cout<<"2.Celsius to Fahrenheiut\n\n";
    cout<<"Fahrenheit to Celsius\n\n";
    cout<<"Enter Fahrenheit: ";
    cin>>num1;

    Fa1=num1 - 32;
    Fa2=Fa1 * 5/9;

    cout<<"\nCelsius:";
    cout<<Fa2 << "\n";

    cout<<"Celsius to Fahrenheit\n\n";
    cout<<"Enter Celsius: ";
    cin>>num1;

    Ce1=num1 * 1.8;
    Ce2=Ce1 + 32;

    cout<<"\nFahrenheit: ";
    cout<<Ce2;

    system("PAUSE > nul");
}

Last edited on
"Press any key to continue...."

Use system("pause"); and the header stdlib.CAUTION: This will work only in Windows.
system("PAUSE > nul");

This will cause the output(i.e."Press any key to continue....") to be redirected to a (new) file called "nul", and not the screen. But it will have the same effect sans the words.

Doesn't main() return an int ?????

Try using brackets for such kind of statements:
Fa1 * 5/9

P.S. I do not remember the precedence table.

cout<<"Celsius to Fahrenheit""\n""\n";
cout<<"Enter Celsius:";
cin>>num1;

Is the last line num1 or num2 ???, you have declared num2, but haven't used it.

how can i put spaces in the Celsius to Fahrenheit

I think you wan't this: cout<<"\nCelsius to Fahrenheit\n\n";

closed account (zb0S216C)
main( ) shouldn't return void. Instead, it should return an int. It's important that you initialize all variables prior to use.

Dams, what you're saying doesn't make any sense. You're basically saying this: Fa2 = [ Fa1 * 5/9 ].
I think you mean parentheses. The sub-script operator (brackets) are used on arrays only.

Benboi, I personally suggest that you use std::endl instead of \n. Also, don't use system( ). If you want the classic Press any key to continue, create a separate function such as this:

1
2
3
4
5
6
7
8
9
10
11
12
void Pause( void )
{
    std::cout << "Press any key to continue..." << std::endl;
    std::cin.ignore( std::numeric_limits < std::streamsize >::max( ), '\n' );
}

int main( )
{
    // ...
    Pause( );
    return 0;
}

As for your issue, just use your space-bar. Whitespace within string literals isn't ignored. As far as I know of, there isn't an escape sequence for a space.

Wazzak
Last edited on
Framework wrote:
I think you mean parentheses.

Yes. I meant parenthesis. Makes the code more readable.

benboi wrote:
i am noob

So, you obviously did not under stand this: std::cin.ignore( std::numeric_limits < std::streamsize >::max( ), '\n' );
ignore is a function that take 2 arguments (max. no. of char. to discard, terminator for the function).
std::numeric_limits < std::streamsize >
This is a template initialization. Read about std::numeric_limits<> for max().

The above code will require you to press 'ENTER' unlike system("pause").
system("pause") is better for such a program.
Last edited on
Topic archived. No new replies allowed.