TO: C++

Page 2 - Seeking answers? Join the AnandTech community: where nearly half-a-million members share solutions and discuss the latest tech.

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: WobbleWobble
Originally posted by: Goosemaster
Originally posted by: WobbleWobble
Originally posted by: Goosemaster
I am not familar with getch:(

<--nooB

I'm assuming you're starting a basic programming class. Just stick with cin or else your teacher might question the usage of getch() (like you're getting help from external sources :p)

#include <conio.h>
...
char m;
m = getch();

thanks

this proggy..she is going to be a bute:D

getch() works differently in Visual C++, if I remember correctly

I am doing straigh c++ in dev-c++
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
so far this is what I have and it screws up

when i run it I get
Please select which type of convers
a)Celsius to Fahrenheit
b)Fahrenheit to Celsius
a
Press any key to continue . . .
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
Originally posted by: Goosemaster
so far this is what I have and it screws up

when i run it I get
Please select which type of convers
a)Celsius to Fahrenheit
b)Fahrenheit to Celsius
a
Press any key to continue . . .

Don't put the { } in your case statement
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
When I remove the brackets it will compile but whne I run the app it give me this

Please enter a celsius value.
the value you entered was4.24399e-314
that equals 32degrees fahrenheit
Press any key to continue . . .

It pull it out of no where:(
 

screw3d

Diamond Member
Nov 6, 2001
6,906
1
76
Wait till you start playing with pointers :D

I think I will kill myself the next time I see another segmentation fault.
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: screw3d
Wait till you start playing with pointers :D

I think I will kill myself the next time I see another segmentation fault.

:(


have any ideas why my program doesn't recognize that last 'cin' ?
 

WobbleWobble

Diamond Member
Jun 29, 2001
4,867
1
0
Originally posted by: Goosemaster
have any ideas why my program doesn't recognize that last 'cin' ?

n was decared as an int, not a char

No more help from me now. You finish your homework ;)
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
OMG thank you :D


it was so simple...:p


Not homework actually....just something I am trying to do for extra credit of sorts
 

Legendary

Diamond Member
Jan 22, 2002
7,019
1
0
Originally posted by: Goosemaster
OMG thank you :D


it was so simple...:p


Not homework actually....just something I am trying to do for extra credit of sorts

If you want to make it so you don't have to press Enter, instead of doing:
cin >> m;
you can do:
m = getch();

this will make it so that Enter is not necessary.
 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
Originally posted by: Legendary
Originally posted by: Goosemaster
OMG thank you :D


it was so simple...:p


Not homework actually....just something I am trying to do for extra credit of sorts

If you want to make it so you don't have to press Enter, instead of doing:
cin >> m;
you can do:
m = getch();

this will make it so that Enter is not necessary.

I don't want to use it since we don't know it:eek:


 

Goosemaster

Lifer
Apr 10, 2001
48,775
3
81
So far I got it all working but alas, I wantt more. I am trying to create a while loop.

here is what I posted in ot:

#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main()
{
double celsius;
double fahrenheit;
char m ;
char n;

//program introduction. Asks for confirmation to continue
cout << "WELCOME TO THE ULTRACONVERTOR 3000, YOUR SOURCE FOR TEMPERATURE CONVERSION," << endl;
cout << "FUFILLING ALL YOUR TEMPERATRUE NEED SINCE 1955" << endl;
cout << "\nWOULD YOU LIKE ME TO CONVERT TEMPERATURES TODAY?" << endl;
cout << "TYPE YES OR NO TO CONTINUE" << endl;
cin >> m;

//decides whether they typed yes or no by simply checking the first letter
switch( m ) {
case 'y':
case 'Y':
cout << "\n\n\ngreat, let's get started!" << endl;
//if yes, the temp. program begins asking user for which task to proceed with
cout << "\n\nPlease select which type of conversion you would like to proceed with:" << endl;
cout << "a)Celsius to Fahrenheit \nb)Fahrenheit to Celsius \nc)I'm done" << endl;
cin >> n;

switch (n)

//first case executes the celsius to fahrenheit conversion module


//while loop that will repeat the program until I select option c
do

{

case 'a':
case 'A':
cout << "Let's get started!" << endl;
cout << "Please enter a celsius value." << endl;
cin >> celsius;

fahrenheit = ((9.0/5)*celsius) + 32;

cout << "the value you entered was " << celsius << endl;
cout << "that equals "<< fahrenheit << " degrees fahrenheit" << endl;
break;

//second case executes the fahrenheit to celsius conversion module
case 'b':
case 'B':
cout << "Let's get started!" << endl;
cout << "Please enter a fahrenheit value." << endl;
cin >> fahrenheit;

celsius = (5.0/9)*(fahrenheit - 32);

cout << "the value you entered was" << fahrenheit << endl;
cout << "that equals "<< fahrenheit << "celsius" << endl;


cout << "thank you for using the ULTRACONVERTOR 3000" << endl;

}

while ( n!= c)


cout << "thank you for using the ULTRACONVERTOR 3000" << endl;


//if not, the program identifies their answer as a no and the program ends
break;
case 'n':
case 'N':
cout << " too bad." << endl;
break;
default:
cout << "too bad" << endl;
break;

}



//fin
system ("PAUSE");

}

the bolded part is what is not working. I have chekced and EVERYTHING is working minus the while loop which I just added