![]() |
| | >>> Click
here to download Final Fantasy Ringtones |
| |
#1 Hey all i'm having some trouble here on a particular assignment. I should be able to do this just fine, but the teacher I have is just so dull, boring, and rude that I can't quite get anything, nor can most of my other classmates. I'm not even sure if she even really knows what she's doing a couple of my classmates had to correct several times on some equations. I'm supposed to be tranlating a pseudocode into C++ in M Visual studio I think I may remember the basic codes I'm supposed to put in, but I need a little help here with a couple of these stepos. There are 6 in total, butI'll just list three of them here to just get an understanding. Step1: Declare a double variable named miles with inital value 100; Step2: Declare a double constant named MILE_TO_KILOMETER with value 1.609; Step 3: Declare a double variable named kilometer multiply miles and MILE_TO_KILOMETER and assign the result to kilometer. I'll appreciate all the help I can get. |
| | |
| |
| Recognized Member | You need to declare your variables using the form: [optional modifiers] [type] [name] = [value]; for example, "const char* string = 'hello\n';" Step 1: Your type is double and your value is 100. Step 2: Same process again, only it has to be made constant. Step 3: You don't have to hardcode your values in variable assignment and you can perform calculations in the process. You can easily assign the value 100*30 to a variable or assign something like length*height, where length and height are predeclared. |
| | |
| | my troubles with the software have gone, but there's an issue here that i'm having with cases. I'm supposed to be adding a question to the code below that allows the user to choose if they want to do an addition subtraction, mulitiplication, or division problem. I got some help from someone else that says that I need something like this in here. I'm wondering where exactly this should be put in the code and where I should replace some text with the math option of my choice. Code: #include Code: #include Edit: Take note that i did post the < iostream > etc part. For some reason this site doesn't show them. Last edited by Depression Moon; 06-19-2009 at 11:01 PM.. |
| | |
| | Eww, I've always hated switch. You can do so much more with if statements...But anyways, there are two routes you can go with this. You could have 4 separate Y/N questions that ask "Would you like to do an addition problem?" etc. Or you could do a strcmp and actually have the user type out what they want. That portion of the code could look something like this: Side note: I'm weird and use printf and scanf instead of cin and cout. I would show you this with cout if I knew the syntax, but I don't. Sorry. I'm pretty sure it's similar, though. Code: #include string.h //obviously, put in the carrot things
int main
{
char questiontype[21]; //declare a string that takes users input
//your code
//when you get to the part where they choose:
printf("Would you like to do addition, subtraction, multiplication, or division?\n");
printf("Type in all lowercase letters, and don't misspell anything.\n");
scanf("%21[^\n]", questiontype); //user types what kind of question
flushall(); //required for scanf
if(strcmp(questiontype, "addition") == 0) //if string that took user input is identical to the phrase "addition"
{
//whatever you do to make the questions about addition
}
if(strcmp(questiontype, "subtraction") == 0) //if string that took user input is identical to the phrase "addition"
{
//whatever you do to make the questions about subtraction
}
//repeat for division and multiplication Code: int compare;
//code
compare = strcmp(questiontype, "addition");
switch
{
case 0: //if questiontype is identical to "addition"
//do stuff
break;
default:
break;
}
//then repeat for the other operations. ![]() |
| | |