PDA

View Full Version : Can anyone help me?



kool_kat_os
March 5th, 2008, 12:18 AM
I am writing a small c++ app. in Win32 API

here is the code:


//Temprature Conversion Program
//Created by Aakash Patel
using namespace std;
#include <iostream>
int main ()
{
int temp;
system ("color F0");
system ("title Temprature Converter");
cout << "Welcome to the Temprature Conversion Program\n";
cout << "Author: Aakash Patel\n";
cout << "-----------\n";
cout << "Please select the temprature that you would like to convert from: \n";
cout << "Press 1 for Fahrenheit\n";
cout << "Press 2 for Celcius\n";
cout << "Press 3 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Celcius\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in fahrenhiet is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << (temp-32.00)*5.00/9.00 << "\n";
system ("PAUSE");
return 0;
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in farenhiet is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp+459.67)/9.00/5.00 << "\n";
system ("PAUSE");
return 0;
}
}
if (temp == 2)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << temp*9.00/5.00+32.00 << "\n";
system ("PAUSE");
return 0;
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp*9.00/5.00)+32.00 << "\n";
system ("PAUSE");
return 0;
}
}
if (temp == 3)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << (temp*1.80)-459.67 << "\n";
system ("PAUSE");
return 0;
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << temp-273.15 << "\n";
system ("PAUSE");
return 0;
}
}
}





i have these thing in it
system ("PAUSE")

how do i make it so that it says "press q to quit" or "press r to restart"???

mike_g
March 5th, 2008, 12:26 AM
Instead of system("pause"); perhaps something like:


#include <cctype> //Include header for tolower function
char ch;
do
{
cout << "press q to quit or r to restart\n";
cin.get(ch);
tolower(ch);
}(while (ch != 'q') && (ch != 'r'));


I havent tested it, but it might give you an idea :)

It might work well if you wrap it in a function too.

kool_kat_os
March 5th, 2008, 12:32 AM
Instead of system("pause"); perhaps something like:


#include <cctype> //Include header for tolower function
char ch;
do
{
cout << "press q to quit or r to restart\n";
cin.get(ch);
tolower(ch);
}(while (ch != 'q') && (ch != 'r'));


I havent tested it, but it might give you an idea :)

It might work well if you wrap it in a function too.

where do i put it?
(i know where the cctype goes, but everything else)

EDIT: I got it...it doesnt work

kool_kat_os
March 5th, 2008, 12:40 AM
when i press "r " it it exits

mike_g
March 5th, 2008, 12:54 AM
If you want to repeat your program you will want to put it all in a main loop. EG:

char repeat = 'r';
while(repeat != 'q')
{
//Code goes here

do
{
cout << "press q to quit or r to restart\n";
cin.get(repeat);
tolower(repeat);
}(while (repeat != 'q') && (repeat != 'r'));
}
This would make all the code in the outer loop repeat until the user enters 'q' at the prompt.

kool_kat_os
March 5th, 2008, 01:08 AM
ok...uh....forget about the restart part....i just want to make it say..."press q to quit"

LaRoza
March 5th, 2008, 01:09 AM
ok...uh....forget about the restart part....i just want to make it say..."press q to quit"

Then make it say that...

kool_kat_os
March 5th, 2008, 01:16 AM
char ch;
do
{
cout << "press q to quit\n";
cin.get(ch);
tolower(ch);
}while (ch != 'q');

when i get to this part it says press q to quit twice

EDIT: what does the ! stand for?

kool_kat_os
March 5th, 2008, 01:20 AM
here is a screenshot

EDIT: i just realized i spelled Fahrenheit wrong

mike_g
March 5th, 2008, 01:21 AM
Ok, here you go:

//Temprature Conversion Program
//Created by Aakash Patel
using namespace std;
#include <iostream>
#include <cctype>
int main ()
{
char restart = 'r';
while(restart != 'q')
{
int temp;
system ("color F0");
system ("title Temprature Converter");
cout << "Welcome to the Temprature Conversion Program\n";
cout << "Author: Aakash Patel\n";
cout << "-----------\n";
cout << "Please select the temprature that you would like to convert from: \n";
cout << "Press 1 for Fahrenheit\n";
cout << "Press 2 for Celcius\n";
cout << "Press 3 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Celcius\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in fahrenhiet is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << (temp-32.00)*5.00/9.00 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in farenhiet is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp+459.67)/9.00/5.00 << "\n";
}
}
if (temp == 2)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << temp*9.00/5.00+32.00 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp*9.00/5.00)+32.00 << "\n";
}
}
if (temp == 3)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << (temp*1.80)-459.67 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << temp-273.15 << "\n";
}
}

do
{
cin.ignore();
cout << "press q to quit or r to restart\n";
cin.get(restart);
tolower(restart);
}while ((restart != 'q') && (restart != 'r'));
}
return 0;
}
I hope you will check out the code and work out what it does as loops are very useful to know in programming.

One problem you had was that you were returning from main before you got to the end of your program.

Also, its best to keep stuff that dosent specifically need to be in if statements out of it as you can save on a lot of repetitive code that way and it makes your prog easier to read.

Hope that helps.

kool_kat_os
March 5th, 2008, 01:24 AM
I hope you will check out the code and work out what it does as loops are very useful to know in programming.

One problem you had was that you were returning from main before you got to the end of your program.

Also, its best to keep stuff that dosent specifically need to be in if statements out of it as you can save on a lot of repetitive code that way and it makes your prog easier to read.

Hope that helps.

i new to programming...so thanks alot:) ill try it

nanotube
March 5th, 2008, 01:25 AM
EDIT: what does the ! stand for?

!= means "not equal"

kool_kat_os
March 5th, 2008, 01:30 AM
Ok, here you go:

//Temprature Conversion Program
//Created by Aakash Patel
using namespace std;
#include <iostream>
#include <cctype>
int main ()
{
char restart = 'r';
while(restart != 'q')
{
int temp;
system ("color F0");
system ("title Temprature Converter");
cout << "Welcome to the Temprature Conversion Program\n";
cout << "Author: Aakash Patel\n";
cout << "-----------\n";
cout << "Please select the temprature that you would like to convert from: \n";
cout << "Press 1 for Fahrenheit\n";
cout << "Press 2 for Celcius\n";
cout << "Press 3 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Celcius\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in fahrenhiet is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << (temp-32.00)*5.00/9.00 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in farenhiet is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp+459.67)/9.00/5.00 << "\n";
}
}
if (temp == 2)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << temp*9.00/5.00+32.00 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp*9.00/5.00)+32.00 << "\n";
}
}
if (temp == 3)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << (temp*1.80)-459.67 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << temp-273.15 << "\n";
}
}

do
{
cin.ignore();
cout << "press q to quit or r to restart\n";
cin.get(restart);
tolower(restart);
}while ((restart != 'q') && (restart != 'r'));
}
return 0;
}
I hope you will check out the code and work out what it does as loops are very useful to know in programming.

One problem you had was that you were returning from main before you got to the end of your program.

Also, its best to keep stuff that dosent specifically need to be in if statements out of it as you can save on a lot of repetitive code that way and it makes your prog easier to read.

Hope that helps.

it sometimes works right when you select specific conversions...but others....no

mike_g
March 5th, 2008, 01:34 AM
Hmm.. Well i think the problems somewhere else in your code as I removed all the return 0 statements from in the if statements.

Good luck with it ;)

kool_kat_os
March 5th, 2008, 01:39 AM
Ok...now i jsut tring to make it quit with the q thing...i was messing around...what wrong?


//Temprature Conversion Program
//Created by Aakash Patel
using namespace std;
#include <iostream>
#include <cctype>
int main ()
{
char quit = 'q';
{
int temp;
system ("color F0");
system ("title Temprature Converter");
cout << "Welcome to the Temprature Conversion Program\n";
cout << "Author: Aakash Patel\n";
cout << "-----------\n";
cout << "Please select the temprature that you would like to convert from: \n";
cout << "Press 1 for Fahrenheit\n";
cout << "Press 2 for Celcius\n";
cout << "Press 3 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Celcius\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in fahrenhiet is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << (temp-32.00)*5.00/9.00 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in fahrenhiet that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in farenhiet is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp+459.67)/9.00/5.00 << "\n";
}
}
if (temp == 2)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << temp*9.00/5.00+32.00 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in celcius that you would\n";
cout << "like to convert to kelvin\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in celcius is: " << temp << "\n";
cout << "That temprature converted to kelvin is: " << (temp*9.00/5.00)+32.00 << "\n";
}
}
if (temp == 3)
{
int temp;
cout << "Please select the temprature that you would like to:\n";
cout << "Press 1 for Fahrenhiet\n";
cout << "Press 2 for Celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
if (temp == 1)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to fahrenhiet\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to fahrehiet is: " << (temp*1.80)-459.67 << "\n";
}
if (temp == 2)
{
int temp;
cout << "Please enter the temprature in kelvin that you would\n";
cout << "like to convert to celcius\n";
cout << "> ";
cin >> temp;
system ("cls");
cout << "The temprature you entered in kelvin is: " << temp << "\n";
cout << "That temprature converted to celcius is: " << temp-273.15 << "\n";
}
}

do
{
cin.ignore();
cout << "press q to quit\n";
cin.get(quit);
tolower(quit);
}while ((quit != 'q'));
}
return 0;
}


EDIT: i dont know what i doing

LaRoza
March 5th, 2008, 01:44 AM
EDIT: i dont know what i doing

I see.

Perhaps you should start over again, and try to understand what you are doing before doing it.

kool_kat_os
March 5th, 2008, 01:46 AM
I see.

Perhaps you should start over again, and try to understand what you are doing before doing it.

im talking about the stuff i added because the guy told me to in this thread....i know what everything else does.

bben
March 5th, 2008, 01:50 AM
cout << "Please enter the temprature in fahrenhiet that you would\n";

Nothing to do with the actual code, but "temperature" "Fahrenheit"... :KS

Oh, and Kelvin, Celcius and Fahrenheit need CAPS

hey, it's all part of debugging :P
no offence btw!

kool_kat_os
March 5th, 2008, 01:58 AM
cout << "Please enter the temprature in fahrenhiet that you would\n";

Nothing to do with the actual code, but "temperature" "Fahrenheit"... :KS

Oh, and Kelvin, Celcius and Fahrenheit need CAPS

hey, it's all part of debugging :P
no offence btw!

thanks anyway...i was in a hurry so i just copy and pasted the rest:)