Go Back   PCMech Forums > Help & Discussion > Web Design / Development

Need Some Help? Type Your Keywords Here:

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Old 02-07-2006, 06:42 PM   #1
Member (9 bit)
 
Join Date: Apr 2005
Location: Michigan
Posts: 346
Send a message via AIM to barch 88
Need some help with a Programming Code...PLEASE!

Ok, I'm using Dev C++ game programming software and I need someone to help me write a code... this is what my teacher gave me, sorry if it's not too clear I really don't understand it..

Ok;
Quote:
Write a code for the following exercise:

Input two numbers.

Multiplay the numbers together and print the result in the form:

"The product of __ and __ is __."

Be sure to include proper spacing and punctuation.

Add the numbers together and print the result in the form:

"The sum of __ and __ is __."

Instruct the user to press enter to exit the program.
Here is some of the tips he gave us.

Quote:
#include
Int main()
{
Int first_num;

cout << "Enter an integer between 1 and 10: ";
cin >> first_num;
cout << "\n\nEnter second_num";
cout << "The sum of __ and __ is " << first_num+second_num << ".h"
}
I really need help with this is an assignment and it's due tomorrow and yes, i've tryed to figure out out for the past hour... and still nothing. I'd be very grateful for any help.

-Edit-
Here is a code I just tryed and it gave me a couple of errors;
Quote:
#include
using namespace std;

int main()
(
int first_num;

cout << "Enter an integer between 1 and 10: ";
cin >> first_num;
cout << "\n\nEnter second_num";
cout << "the sum of _ and _ is " << first_num + second_num << ".h";

std::cout << "Press the ente key to exit";
std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);
return 0;
}//end line
Here are the errors;
Quote:
Line 11 C:\Dev-Cpp\Examples\Hello\Assignment 1.3.cpp parse error before `;' token

line 19 C:\Dev-Cpp\Examples\Hello\Assignment 1.3.cpp `main' declared as function
If anyone can tell me how to fix those then that would be apprecieated as well.
__________________
< Antec 1200 | ASUS Rampage III Extreme | Intel Core i7-920 w/ Noctua cooler @ 3.1 GHz | Corsair Dominator's 6GB| (2) Sapphire HD 5770's in CrossfireX | WD Raptor 74GB | WD Caviar Black 1TB | Corsair HX850W >
barch 88 is offline   Reply With Quote
Old 02-07-2006, 07:58 PM   #2
Barefoot on the Moon!
Staff
Premium Member
 
Force Flow's Avatar
 
Join Date: Aug 2002
Location: Northeastern USA
Posts: 13,385
I don't know C++, but it looks like you have a parenthesis instead of a bracket below the constructor for int main(). That may take care of one of the errors.
__________________
There are two secrets to staying young, being happy, and achieving success. You have to laugh and find humor every day, and you have to have a dream.
Force Flow is offline   Reply With Quote
Old 02-07-2006, 08:46 PM   #3
Member (9 bit)
 
colecifer's Avatar
 
Join Date: Jan 2004
Location: Kansas City(westwood), KS
Posts: 458
I know exactly how to do this in java but c++ isn't something i've messed with it. One thing i can't help but notice, it doesn't look like you multiply anywhere in there and product means multiplication. I can show you the java code if you like but you'd have to know how to adapt it.

EDIT
Also i see you declare first_num as a variable but i don't see you declare second_num anywhere.
colecifer is offline   Reply With Quote
Old 02-07-2006, 09:49 PM   #4
Member (9 bit)
 
Join Date: Apr 2005
Location: Michigan
Posts: 346
Send a message via AIM to barch 88
Yeah, I can try the Java Code if you can give it that would be great.

Let me mess with it some more...
barch 88 is offline   Reply With Quote
Old 02-08-2006, 04:02 AM   #5
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
change "(" to "{" after "int main()"

first off variable "second_num" is not declared; you have to declare a variable before you can use it in C++;
like "int second_num;"
it also has no input statement, meaning no value.you need some thing like:
cin >> second_num;
now for the output:
what the hell is ".h" anyway?????(sorry for the language)
you probably mis-read it from ".\n"
adding( SUM ) output statement should be:
cout << "The sum of " << first_num << " and " << second_num << " is " << first_num+second_num << ".\n";

for multiplying(PRODUCT) :
cout << "The product of " << first_num << " and " << second_num << " is " << first_num*second_num << ".\n";

-----
HTH.
__________________
words to live by:
others don't know, I know.
others know, I know more.
others know more, I excel.
one shouldnt read this far; above, is meant as an encouragement, translated from a Chinese Proverb.
"He who angers you conquers you." : Elizabeth Kenny

Last edited by alfie2; 02-08-2006 at 04:22 AM.
alfie2 is offline   Reply With Quote
Old 02-08-2006, 11:31 AM   #6
Member (6 bit)
 
Join Date: Feb 2006
Location: MA
Posts: 43
#include <.iostream>
Int main()
{
Int first_num;
Int second_num;

cout << "Enter an integer between 1 and 10: ";
cin >> first_num;
cout << "\n\nEnter second number: ";
cin>> second_num;

cout << "The product of " << first_num << " and " << second_num << " is " << first_num*second_num << ".\h";

cout << "The sum of " << first_num << " and " << second_num << " is " << first_num+second_num << ".\h";

exitcomm();

}
void exitcomm(){
cout << "Press enter to exit...";
getchar();getchar();}

Hope this help. This is how it should look like... pretty basic. But, I do tend to make a lot of mistake in basic coding.

--.h is correct, it's a form of a standard string... correct me if i am wrong

--you need to include because you using input from the keyboard and output... take out the . because forum text won't show if i didn't put it in there

--add a function at the end calling the exit method
Nav_functions is offline   Reply With Quote
Old 02-08-2006, 02:17 PM   #7
Member (9 bit)
 
Join Date: Apr 2005
Location: Michigan
Posts: 346
Send a message via AIM to barch 88
Thank You.
barch 88 is offline   Reply With Quote
Old 02-08-2006, 03:43 PM   #8
Member (9 bit)
 
Join Date: Feb 2005
Posts: 392
nav:
what does "\h" do? in my 20 years of programming, I never hear of it.
"\n" is end of line, but "\h" simply prints an "h" at the end of the sentence without producing a new line, so the next "cout" statement will be printed appeneded to it.
lets refresh: In C\C++
Escape Sequence Represents
\a Bell (alert)
\b Backspace
\f Formfeed
\n New line
\r Carriage return
\t Horizontal tab
\v Vertical tab
\' Single quotation mark
\" Double quotation mark
\\ Backslash
\? Literal question mark
\ooo ASCII character in octal notation
\xhhh ASCII character in hexadecimal notation
alfie2 is offline   Reply With Quote
Old 02-09-2006, 10:18 AM   #9
Member (6 bit)
 
Join Date: Feb 2006
Location: MA
Posts: 43
Alfie2 you might be right on that one. If you have done coding for 20 years... I take your word and judgment on it.

From my knowledge .h itself is an extension... i.e. stdio.h, which is use in a standard i/o. Let's just leave it at that, it was my poor judgment to overlooked the codes.
Nav_functions is offline   Reply With Quote
Reply

Bookmarks

Still Need Help? Type Your Keywords Here:


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 -5. The time now is 05:04 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 PL2