EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Archive::Development (https://www.eqemulator.org/forums/forumdisplay.php?f=621)
-   -   Junior Developer Code (https://www.eqemulator.org/forums/showthread.php?t=13975)

kugrug 05-25-2004 03:02 PM

Junior Developer Code
 
#include <iostream>
int main ()
{
int a, b ,c;
std::cout << "Enter 2 Numbers to Add
";
cin >> a;
cin >> b;
c=(a+b);
std::cout << "Sum is = " << c;
int x;
std::cin >> x;
return 0;
}


also this, but i dont know how to make it keep going, like change days every 24 hours, but hey you can change it every morning if you like


#include <iostream>
int main ()
{
enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday };
Days today;
today = Wednesday;
if (today == Sunday || today == Saturday)
std::cout << " Woot Weekends!";
else
std::cout << "Damn School. Today is" << today;
int x;
std::cin >> x;
return 0;
}


Now im only 13 so please be polite and not critisize(no idea how to spell) But im working on C++ and i wanna help cuz me be bored

mangoo 05-25-2004 03:39 PM

I think what they were looking for are cope snippets of bug fixes for the emulator. Not your high school class tutorials :D .

kugrug 05-25-2004 04:08 PM

im not in high school yet

mangoo 05-25-2004 04:29 PM

Ya I didn't pay much attention to the age 13 action there. Anyhow in HS CS the above is what you do everyday / play games.

Scorpious2k 05-25-2004 10:14 PM

Keep working on it and don't give up. You'll get there. And you'll be surprised how fast you learn if you keep at it.

There are a lot of tutorial type sites on the internet. Visit them and try them out. Download the source for the emulator (and keep it up to date). It isn't a good example of "ideal" code, but its a great example of real world code that gets maintained and changed constantly. Check out changes other people post. Look at the code and try to figure it out. Be curious.

Don't get discouraged if you don't get it right away. I like to describe it as like jumping into the deep end of a pool... you are in over your head. Thinking you will never make it up to the air... then, finally you take that deep breath and go "wow! I'm going to do THAT again" :-)

kugrug 05-25-2004 11:53 PM

i just downloaded the source for 5.6 what should i look at, i took a look at guilds and couldnt understand what it was talking about

kugrug 05-26-2004 12:03 AM

Does anyone have a c++ calulator source?

maaltan 05-26-2004 02:30 AM

calculator
 
a very simple calculator, im just typing it in here so you might have to correct some small compile errors, but the logic should be sound.
That would make a good debugging exercise for the trainees :)

I tried leaving pointers out of it .. but hell thats what c runs on you have to learn them eventually.

You will have to break out though its infinate

Code:


#include <stdio.h>

int main()
{
 float oprand;
    float accumulator;
    char buf=' ';

while (1)
{
  printf("Enter a the first number\n");
  scanf("%f", &accumulator);
  buf = ' ';
while (buf != '=')
{
 
  printf("Enter +,-,*, /  Or enter = to get result\n");
  scanf("%s", &buf);

  if (buf != '=')
  {
          printf("Enter next number.\n");
          scanf("%f", &oprand);
  }

  switch (buf)
  {
        case '+':
              accumulator+=oprand;
                          break;
        case '-':
              accumulator-=oprand;
                          break;
        case '*':
              accumulator*=oprand;
                          break;
        case '/':
              accumulator/=oprand;
                          break;
        case '=':
                printf("Result: %f\n", accumulator);
                                break;
        default:
            printf("invalid operator\n"); // have to have it to prevent the program from crashing, you may wish to put debugging info in here
    }

}
}

} // err lost track of braces this might not be needed

well its started out simple .. hope it helps actually it turned out to be c instead of c++ .. eeh it will work in c++ .. replace the printfs and scanfs with cin and cout stream redirections like your use to ..then it be c++ :)

kugrug 05-26-2004 07:04 AM

hey
 
thanks for that, i couldnt get the case command to work before

cofruben 05-26-2004 07:52 AM

Code:

#include <stdio.h>
void Calculator();
int main()
{
        Calculator();
        return 0;
}
void Calculator(){
        int x=0; //  for the loop
        printf("Starting Calculator...\n");
        float numbertwo;
    float numberone;
        char action;
        float result=0;

        while(x==0){
                printf("Enter the first number:  ");
                scanf("%f", &numberone);
                printf("\nEnter +,-,* or / :        ");
                scanf("%c", &action);
                scanf("%c", &action);
                printf("\nEnter the second number:  ");
                scanf("%f",&numbertwo);

                switch (action)
                {
                                case '+':
                                          result=numberone+numbertwo;
                                        break;
                                case '-':
                                          result=numberone-numbertwo;
                                        break;
                                case '*':
                                          result=numberone*numbertwo;
                                        break;
                                case '/':
                                        result=numberone/numbertwo;
                                        break;
                                default:
                                        printf("invalid operator\n"); // non-valid character.
                                        x=1;
                }
                printf("                          --------\n");
                printf("                          %f\n\n",result); //  prints the result
        }
}

simple code.

kugrug 05-26-2004 08:55 AM

hey i tried make it the way i coud read it so far no errors but when i try to execute it doesnt do anything


#include <stdio.h>
#include <iostream>
int main ()
{
float numberone;
float numbertwo;
char action;
int x=0; // loop
float result=0;
while (x==0){
std::cout << "Enter 1st First Number ";
cin >> numberone;
std::cout << "\nEnter +,-,* or / : ";
cin >> action;
std::cout << "\n Enter Second Number ";
cin >> numbertwo;
switch (action)
{
case '+':
result=numberone+numbertwo;
break;
case '-':
result=numberone-numbertwo;
break;
case '*':
result=numberone*numbertwo;
break;
case '/':
result=numberone/numbertwo;
break;
default:
std::cout << "invalid operator\n"; // non-valid character.
x=1;
}
std::cout << " --------\n";
std::cout << " %f\n\n",result; // prints the result
int b;
std::cin >> b;
return 0;
}
}

maaltan 05-26-2004 09:20 AM

hrm .. i think i remember something in the rules about not helping people learn how to code in this forum, maybe a moderator can move this thread to misc or something...


anyway. Im using vc++. i got several compile errors. this is pretty normal. Your code might be fine but vc++ is insane i think .. couple of quick things you might try though

first change your include to :

#include <iostream.h>

and remove the std:: from the stream access commands

so just put:

cin >> blah;

cout << "this is blabhblablabh";

again im rusty when using the iostreams so this might not be correct.

also, i don't think you can use printf formatting keys with the streams. you have to piece together a fully formated string (using sprintf maybe) and pass it to cout. I might be wrong on this .

-------

ok i am editing my post. I just checked out cout

your statement :

cout << " %f\n\n",result; // prints the result

should read:

cout << result << "\n\n"; // prints the result

that makes it work.

kugrug 05-26-2004 10:13 AM

Hey same problem but this time it crashes or lags


All times are GMT -4. The time now is 09:21 AM.

Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.