Welcome to Eyes on FF!
>>> Click here to download Final Fantasy Ringtones
Oh no!
 

 
LinkBack Thread Tools
Depression Moon
Hypnotic
Depression Moon's Avatar
Location: Lavender Town
#1
Default Coding help

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.
Old 05-29-2009, 06:45 PM
Reply With Quote
Depression Moon is offline  
Aerith's Knight
Not evil, just bored
Aerith's Knight's Avatar
Location: The Netherlands
Default

I'm a python programmer myself, but assigning variables and constants is about the simplest action in any programmer language. Either check your lesson material for 3 seconds or google it.
Old 05-29-2009, 08:43 PM
Reply With Quote
Aerith's Knight is offline  
o_O
Recognized Member
nerd
o_O's Avatar
Location: New Zealand
Default

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.
Old 06-03-2009, 05:16 PM
Reply With Quote
o_O is offline  
NeoTifa
diafnaoplzkthnxbai
NeoTifa's Avatar
Location: in psy's panties <3
Default

double miles = 100;
constant double MILE_TO_KILOMETER = 1.609;
double kilometer = miles * MILE_TO_KILOMETER;
>>cout kilometer;

???? It's been a while
Old 06-08-2009, 02:26 AM
Reply With Quote
NeoTifa is offline  
o_O
Recognized Member
nerd
o_O's Avatar
Location: New Zealand
Default

Code:
cout << kilometer;
But you don't learn anything from having your homework done for you.
Old 06-08-2009, 02:49 AM
Reply With Quote
o_O is offline  
Depression Moon
Hypnotic
Depression Moon's Avatar
Location: Lavender Town
Default

I had this done last wekk thank you all for your help and I think you can learn from others help, it certainly helped me and that wasn't the entire thing like I said.
Old 06-08-2009, 03:17 AM
Reply With Quote
Depression Moon is offline  
Depression Moon
Hypnotic
Depression Moon's Avatar
Location: Lavender Town
Default

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 

int main(void)
{
  int choice = 2;                 


  if((choice>10) || (choice <1)){
    choice = 11;                 
  }   

  switch(choice)
  {
    case 7:
      printf("\nCongratulations!");
      break;                    

    case 2:
      printf("\nA");
      break;                      

    case 8:
      printf("\nB");
      break;     

    case 11:
      printf("\nC");

    default:
      printf("\nSorry, you lose.\n");
      break;             
  }
Code:
#include 
#include   // For time function
#include  // For rand and srand functions
using namespace std;

int main()
{
char continueLoop = 'Y';
while (continueLoop == 'Y')
{
// Execute body once
long startTime = time(0);
int correctCount = 0; // Count the number of correct answers
int incorrectCount = 0;
int count = 0; // Count the number of questions

while(count < 4)
{
//generate random numbers
    srand(time(0));
    int number1 = rand() % 10;
    int number2 = rand() % 10;

//if number 1 < number 2, swap
    if(number1
    {
        int temp = number1;
        number1 = number2;
        number2 = temp;
    }

//ask question "what is number1 - number2?"
    cout << "What is " << number1 << " - " << number2 << "?";
    int answer;
    cin >> answer;

//see if answer is correct

    if (number1-number2 == answer)
    {
        cout << "You are correct!\n";
        correctCount++;
    }
    else
    {
        cout << "Your answer is wrong.\n" << number1 << " - " <<
        number2 << " should be " << (number1 - number2) << endl;
incorrectCount++;
    }

// Increase the count    
count++;
//ask question "what is number1 - number2?"
    cout << "What is " << number1 << " + " << number2 << "?";
    cin >> answer;

//see if answer is correct

    if (number1+number2 == answer)
    {
        cout << "You are correct!\n";
        correctCount++;
    }
    else
    {
        cout << "Your answer is wrong.\n" << number1 << " + " <<
        number2 << " should be " << (number1 + number2) << endl;
incorrectCount++;
    }

// Increase the count    
count++;
//ask question "what is number1 * number2?"
    cout << "What is " << number1 << " * " << number2 << "?";
    cin >> answer;

//see if answer is correct

    if (number1*number2 == answer)
    {
        cout << "You are correct!\n";
        correctCount++;
    }
    else
    {
        cout << "Your answer is wrong.\n" << number1 << " * " <<
        number2 << " should be " << (number1 * number2) << endl;
incorrectCount++;
    }

// Increase the count    
count++;
//ask question "what is number1 * number2?"
    cout << "What is " << number1 << " / " << number2 << "?";
    cin >> answer;
    if (number1 == 0)
    number1 = 1;
    if (number2 == 0)
        number2 = 1;
//see if answer is correct

    if (number1/number2 == answer)
    {
        cout << "You are correct!\n";
        correctCount++;
    }
    else
    {
        cout << "Your answer is wrong.\n" << number1 << " / " <<
        number2 << " should be " << (number1 / number2) << endl;
        incorrectCount++;
    }

// Increase the count    
count++;
}

long endTime = time(0);
long testTime = endTime - startTime;
double correctPercent = (correctCount * 100) / (correctCount + incorrectCount);
cout << "correct count is " << correctCount << "\n";
cout << "incorrect count is " << incorrectCount << "correctPercent is " << correctPercent << "\nTest time is " << testTime << " seconds\n";
// Prompt the user for confirmation
cout << "Enter Y to continue and N to quit: ";
cin >> continueLoop;
}
system("pause");
return 0;
}

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..
Old 06-19-2009, 10:47 PM
Reply With Quote
Depression Moon is offline  
The Unknown Guru
We Must Repeat
The Unknown Guru's Avatar
Location: D-E-V-O!
Default

Originally Posted by Depression Moon ^
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.
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
If you really have to use switch, then you can create an int that will take the value of a strcmp and then put in something like this:
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.
If you have any more questions, feel free to PM me or something. I know C++ pretty well, and I would be happy to help
Old 07-06-2009, 10:24 AM
Reply With Quote
The Unknown Guru is offline  



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:41 PM.

Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0
Copyright ©2000 - 2007, Eyes on Final Fantasy.
Sean Robinson Design

Scholarships | Tool Enhancers