473,396 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

C++ Primer ex 7.15 ambiguous statement

STATEMENT: write a main function that takes two vales as arguments and
print their sum.
the main takes classic arguments ;) int main( int argc, char **argv )

1st argument is an int while 2nd argument is an array of string literals.
how am i supposed to add a string literl to an int ?


--
http://arnuld.blogspot.com

Aug 16 '07 #1
2 1478
arnuld wrote:
STATEMENT: write a main function that takes two vales as arguments and
print their sum.
the main takes classic arguments ;) int main( int argc, char **argv )

1st argument is an int while 2nd argument is an array of string literals.
how am i supposed to add a string literl to an int ?
Maybe convert the strings to an int ?
int x = Convert( "-122" );
int y = Convert( "122" );

int sum = x + y;

??

What does Convert look like ?

What does Convert( "Google" ) do ?

Aug 16 '07 #2
In article <pa****************************@gmail.com>,
arnuld <ge*********@gmail.comwrote:
STATEMENT: write a main function that takes two vales as arguments and
print their sum.
the main takes classic arguments ;) int main( int argc, char **argv )

1st argument is an int while 2nd argument is an array of string literals.
how am i supposed to add a string literl to an int ?
Try this:

int main( int argc, char* argv[] )
{
for ( int i = 0; i < argc; ++i )
cout << argv[i] << '\n';
}

Then run your program using:

program 1 2

You should end up with the following output:

program
1
2

Now all you have to do is figure out how to add the 1 and 2 to produce 3
and output it instead.
Aug 16 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lumpierbritches | last post by:
I'm trying to pull all the parents of a particular animal and I have my SQL statement that says not supported and when I attempt to run the Query, I get The SQL statement couldn't be executed...
11
by: arnuld | last post by:
i have solved the problem but it is quite length. as usual, i wanted some coding-standards or good-design opinions: /* C++ Primer 4/e * chapter 3 - Library Types * exercise 3.13 *...
8
by: arnuld | last post by:
i have solved it. any suggestions for improving the code: /* C++ Primer - 4/e * chapter 3 * exercise 3.14 * STATEMENT read some text into a vector,storing each word as an elelment in the...
5
by: arnuld | last post by:
i have solved the problem. any comments on it: /* C++ Primer 4/e * chapter 3 * * exercise 3.24 * STATEMENT: * consider the sequence 1,2,3,5,13,21. Initialize a "bitset<32>" object that...
9
by: arnuld | last post by:
i think this needs some improvement. /* C++ Primer - 4/e * chapter 4- Arrays & Pointers, exercise 4.30 * STATEMENT * write a programme to concatenate the two C-style strings literals...
33
by: arnuld | last post by:
it works fine. i am posting it to know your views (please remember, i am at chapter 6, so i have not encountered stuf like Functions): /* C++ Primer - 4/e * * exercise 6.20 * STATEMENT * ...
13
by: arnuld | last post by:
it runs fine. any advice for the improvement: /* C++ Primer - 4/e * * exercise 7.20 * STATEMENT: * write a programme to find the factorial of an int. * use an iteratice function. * */
20
by: arnuld | last post by:
I get an error, can't find what is the problem: /* C++ Primer - 4/e * * Chapter 8, exercise 8.3 * STATEMENT * write a function that takes and returns an istream&. the function should read...
12
by: Nathan Sokalski | last post by:
I have several CustomControls that I have written for my project. However, when I try to compile I recieve the following warning & errors: Warning 32 Could not resolve this reference. Could not...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.