Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Newbie!
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Sun Aug 28, 2005 1:28 am   Post subject: Newbie!

ok i know absoluly NOTHING with C++

i want to learn it because im told its an extremly powerful language.

I got the basics down of turing, and instead of learning that 100%, i wish to take up C++

I took a course of Java in school, are they simular?

Anyways, I need a breif run down of commands, or a link to a GREAT! Manual...

I installed the devC++ compiler...

If anyone wants to learn this language with me on msn, send me a PM...
I think if i have someone to help me, and vise versa (depending on how much you know) we can attempt to make simple programs at the same time, and test them...

This is what i did with Turing and it workd great.

Anyways, thanks for the help...
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sun Aug 28, 2005 2:02 am   Post subject: (No subject)

I'm sure that this have been said before -- you'll be in way over your head.

C++ could be considered powerful because you get down and dirty with optimizing your operations.. squizing those extra frames while rendering 3D..

what is it that you plan on developing that is so complex, it will not run fast enough for you?
TokenHerbz




PostPosted: Sun Aug 28, 2005 2:23 am   Post subject: (No subject)

well i would like to make an online 2D game of some sort.

At the moment...

im stuck ....

code:

#include <iostream>

using namespace std;

int main()
{
    int num;
    int num2;
    int ans;
   
    cout<<"Please enter in a number";
    cin>> num;
    cin.ignore();
    cout<<"You entered: "<<num<<"\n";
    cin.get();
    cout<<"Please enter in another number";
    cin>> num2;
    cout<<"Your entered: "<<num2<<"\n";
    ans = num + num2
    cout<<"Your numbers added ="<<ans<<"\n";
    ans = num * num2
    cout<<"Yout numbers times ="<<ans<<"\n";
    cin.get
}


Can you tell me why it wont work?
[Gandalf]




PostPosted: Sun Aug 28, 2005 5:19 am   Post subject: (No subject)

Somebody else will tell you why you shouldn't use C++ this early on. Right now I would probably spout gibberish if I tried.

c++:
#include <iostream>

using namespace std;

int main()
{
    int num, num2;
   
    cout << "Please enter in a number: ";
    cin >> num;
    cout << "You entered: " << num << endl;
    cout << "Please enter in another number: ";
    cin >> num2;
    cout << "Your entered: " << num2 << endl;
    int ans (num + num2);
    cout << "Your numbers added = " << ans << endl;
    ans = num * num2;
    cout << "Your numbers multiplied = " << ans << endl;
    cin.ignore(1, '\n');
    cin.ignore();
}

I did it off the top of my head, so blame the sleepiness for any mistakes. Yep, I tested it - it works. You probably forgot some semicolens somewhere in there.

*edit* fixed some more. 6:20 am is not a good time for writing code...
Mazer




PostPosted: Sun Aug 28, 2005 7:13 am   Post subject: (No subject)

tokenherbz, you are missing a bunch of semi-colons in the code, and in the second last line you seem to have lost the parentheses in the function call to cin.get() (as well as the semi-colon Razz )
wtd




PostPosted: Sun Aug 28, 2005 9:44 pm   Post subject: (No subject)

tokenherbz: yes, C++ is powerful. So are a lot of other languages, and many of them are a fair sight easier to wrap your head around.

Cosider your code... or...

code:
print "Please enter a number "
num = gets.to_i
puts "You entered: #{num}"
print "Please enter another number "
num2 = gets.to_i
puts "You entered: #{num2}"
puts "Your numbers add = #{num + num2}"
puts "Your numbers times = #{num * num2}"


in Ruby.

Food for thought.
TokenHerbz




PostPosted: Tue Aug 30, 2005 1:38 am   Post subject: (No subject)

Nah, i enjoy a challenge...
I am very interested in C++

code:

#include <iostream>

using namespace std;

int main()
{
    int x,y,a;
    int ans;
   
    cout<<"Please enter in a number: \n";
    cin>> x;
 //   cin.ignore();
    cout<<"Please enter in another number: \n";
    cin>> y;
 //   cin.ignore();
    cout<<"Please choose an expression \n";
    cout<<"1 = Times (*) \n";
    cout<<"2 = Plus (+) \n";
    cout<<"3 = Div (/) \n";
    cout<<"4 = Sub (-) \n";
    cin>> a;
   
    if(a == 1) {
         ans = x * y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    if (a == 2){
         ans = x + y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    if (a == 3) {
         ans = x / y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    if (a == 3){
          ans = x - y;
          cout<<"Your answer is"<<ans<<"\n";
    }
    if (a != 1 && a != 2 && 1 != 3 && a != 4){
          cout<<"You didn't follow instructions \n";
    }
    cin.get();
}


If you run this program, it closes at the end, Now, i thought cin.get() keeps it open untill an input, **Like Input.Pause for turing**

Anyways it doesn't, so what do i put down to keep the window open?

I need to see if everythings displaying correctly.
wtd




PostPosted: Tue Aug 30, 2005 1:46 am   Post subject: (No subject)

c++:
    if(a == 1) {
         ans = x * y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    if (a == 2){
         ans = x + y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    if (a == 3) {
         ans = x / y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    if (a == 4){
          ans = x - y;
          cout<<"Your answer is"<<ans<<"\n";
    }
    if (a != 1 && a != 2 && 1 != 3 && a != 4){
          cout<<"You didn't follow instructions \n";
    }


This is problematic because there's nothing to prevent you from changing the value stored in "a". If you do, you may end up evaluating more than one of these cases.

c++:
    if (a == 1) {
         ans = x * y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    else if (a == 2) {
         ans = x + y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    else if (a == 3) {
         ans = x / y;
         cout<<"Your answer is"<<ans<<"\n";
    }
    else if (a == 4) {
          ans = x - y;
          cout<<"Your answer is"<<ans<<"\n";
    }
    else {
          cout<<"You didn't follow instructions \n";
    }


But since we're only comparing a single integer variable for equality...

c++:
switch (a)
{
   case 1:
      cout << "Your answer is" << x * y << endl;
      break;
   case 2:
      cout << "Your answer is" << x + y << endl;
      break;
   case 3:
      cout << "Your answer is" << x / y << endl;
      break;
   case 4:
      cout << "Your answer is" << x - y << endl;
      break;
   default:
      cout << "You didn't follow instructions" << endl;
}


And finally, use meaningful variable names! Smile
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sat Sep 10, 2005 9:04 am   Post subject: (No subject)

Yes, this is old, but for some reason I only noticed it now...

code:
std::cin.ignore();
std::cin.ignore('\n', 1); //The arguments may be backwards


Or, the "bad" (os-specific) way -

code:
system("pause");


*edit* Though you really don't need this - if you are running the program from the command prompt it will automatically keep it open.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 9 Posts ]
Jump to:   


Style:  
Search: