Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C++ N00b question


  • Please log in to reply
10 replies to this topic

#1 keldron

keldron

  • Members
  • 57 posts
  • OFFLINE
  •  
  • Local time:02:20 PM

Posted 15 February 2010 - 08:23 PM

Hello my dear fellow programmers I am new to the whole programming field and currently started taking C++ classes . While I understand most of the basic principles and whatnot the part where I have to write a program scares me and I believe I am not doing it right .

My assignment is to :

For your output , display the values of the two integers and the total . Only use numeric literals 62 and 99 once in the program you write . Note that there is no user input for this program .

Sample output :

First integer : 62
Second integer : 99
Total: 161

Here is the code I wrote so far but I am not 100% sure this is correct :

#include <iostream>
using namespace std;

int main ()
{
int FirstInteger;
int SecondInteger;
int Total;

FirstInteger=62;
cout <<"FirstInteger";
SecondInteger=99;
cout <<"SecondInteger";
Total=FirstInteger + SecondInteger;
cout <<Total;

return 0;
}


What I want the program to do is A) make sure that FirstInteger is 62 , SecondInteger is 99 and the Total is 161
Now I am not sure if I have to define the variables or no ( I believe I did that with int command in the first 3 lines of my code ) but I am not sure what happens when I type FirstInteger=62; <--- does that mean FirstInteger gets 62 ? or does that assign 62 to the FirstInteger variable ???

Also I am not 100% sure that when I type cout <<"FirstInteger"; will I get the value I assigned to the first integer or will I get a display message saying FirstInteger cause I want to see the value not the text .

If anybody with knowledge of C++ could help me out here I would be very very grateful !!!!

Edited by keldron, 15 February 2010 - 08:25 PM.


BC AdBot (Login to Remove)

 


#2 Billy O'Neal

Billy O'Neal

    Visual C++ STL Maintainer


  • Malware Response Team
  • 12,304 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Redmond, Washington
  • Local time:11:20 AM

Posted 15 February 2010 - 09:28 PM

Hello, keldron.

Unfortunately I am not going to help you all that much given that this is homework. If you just cheat, then you aren't actually learning the language.

I will, however, give you a hint. Look around for std::cin.

Billy3
Twitter - My statements do not establish the official position of Microsoft Corporation, and are my own personal opinion. (But you already knew that, right?)
Posted Image

#3 keldron

keldron
  • Topic Starter

  • Members
  • 57 posts
  • OFFLINE
  •  
  • Local time:02:20 PM

Posted 15 February 2010 - 09:32 PM

it's cool man I'm going to my class tomorrow and the teacher will be there to answer any and all questions we have with this assignment you are right though if I cheat or something along these lines I will not learn the language ... at the same time hence I already wrote the code to some degree I dunno if I would consider it cheating at this point .

#4 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:01:20 PM

Posted 15 February 2010 - 09:49 PM

Why walk around confused why not compile, run and verify your program. There are so many C++ compilers on internet.

#5 keldron

keldron
  • Topic Starter

  • Members
  • 57 posts
  • OFFLINE
  •  
  • Local time:02:20 PM

Posted 15 February 2010 - 10:03 PM

How do I go about compiling like I said I am new to this stuff :thumbsup:

#6 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:01:20 PM

Posted 15 February 2010 - 10:13 PM

Download CodeBlocks from : http://www.codeblocks.org/
- After installing, Start CodeBlocks
- Press Ctrl + Shift + N
- Type your code
- Save the file somewhere on your hard disk where you can easily access it, say for example C:\Code. The filename must end in .cpp
- Compile and build the EXE by pressing Ctrl + F9. Similarly, press F9 to build and run the app.

Look under the Build menu for more options.

Edit : If you type system("PAUSE"); just before return 0;, then you can double click on EXE file in the folder and see it work without going in command line.

Edited by Romeo29, 15 February 2010 - 10:15 PM.


#7 keldron

keldron
  • Topic Starter

  • Members
  • 57 posts
  • OFFLINE
  •  
  • Local time:02:20 PM

Posted 15 February 2010 - 10:15 PM

awesome thank you :thumbsup:

#8 keldron

keldron
  • Topic Starter

  • Members
  • 57 posts
  • OFFLINE
  •  
  • Local time:02:20 PM

Posted 15 February 2010 - 10:32 PM

hm... it compiles with no errors and it builds with no errors but when I run it I get this

Process terminated with status -1073741510 (0 minutes, 11 seconds) <--- solved this problem by changing the code a bit

now this code does what I wanted it to do :thumbsup:

#include <iostream>
using namespace std;

int main ()
{
int FirstInteger;
int SecondInteger;
int Total;

FirstInteger=62;
cout <<FirstInteger;
SecondInteger=99;
cout <<SecondInteger;
Total=FirstInteger + SecondInteger;
cout <<Total;

system("PAUSE");
return 0;
}


The only question I have is why is it all on the same line is it cause I did not use endl command ? <--- solved this with the endl command !!!



Nvm figured it out ~!!!!!

#include <iostream>
using namespace std;

int main ()
{
int FirstInteger;
int SecondInteger;
int Total;

FirstInteger=62;
cout <<FirstInteger <<endl;
SecondInteger=99;
cout <<SecondInteger <<endl;
Total=FirstInteger + SecondInteger;
cout <<Total <<endl;

system("PAUSE");
return 0;
}

is my final code and it does exactly what I wanted it to do !!!! AWESOME THX FOR HELP MAN !!!!!!!! YOU MADE MY DAY !!!!!

Edited by keldron, 15 February 2010 - 10:41 PM.


#9 Romeo29

Romeo29

    Learning To Bleep


  • BC Advisor
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:01:20 PM

Posted 16 February 2010 - 08:04 AM

You are welcome for more questions :thumbsup: I see you are learning very fast.

#10 keldron

keldron
  • Topic Starter

  • Members
  • 57 posts
  • OFFLINE
  •  
  • Local time:02:20 PM

Posted 18 February 2010 - 10:12 AM

heh thx I will prolly have more questions as we go through the semester .

#11 KelvinS

KelvinS

  • Members
  • 9 posts
  • OFFLINE
  •  
  • Gender:Male
  • Local time:02:20 AM

Posted 17 June 2010 - 09:10 PM

Good luck boys!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users