473,776 Members | 1,557 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

some problem in C++

6 New Member
Hi , Every one I really need some help in my programs it doesn't work as I want I know there something wrong in it if you know where the wrong is just show me plz as soon as Possible plzzzzz.
I a Beginner in C++ ;

I will be thankful for you .

------------------------
first program : I need the user to enter his/her full name and then the program separate the string to first name , middle name and the last name which stored in three different strings .
I do it like this ....
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<ctype.h>
  5. #include<string.h>
  6. main()
  7. {
  8.     int i = 1, j, d = 0, k, tmp, x;
  9.     char word[10], f[10], m[10], l[10];
  10.  
  11.     cout << "Enter Your Full Name\n";
  12.  
  13.     while (cin >> word) {
  14.         cout.width('\0');
  15.         cout << "\n";
  16.         if (word != '\0') {
  17.             strcpy(f, word);
  18.             cout << "\n Your First Name is.... \n";
  19.             cout << f;
  20.         }
  21.         strcpy(m, word);
  22.         cout << "\n Your Middle Name is.... \n";
  23.         cout << m;
  24.         strcpy(l, word);
  25.         cout << "\n Your Last Name is.... \n";
  26.         cout << l;
  27.     }
  28.     cout << "\n";
  29.     getch();
  30.     return 0;
  31. }
*************** *************** *************** *******
second program: it ask the user to enter three word and then arranges the word in alphabetical order using string function to solve this.
I do it like this ....

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. #include<ctype.h>
  5. #include<string.h>
  6. main()
  7. {
  8.     int i = 1, j, d = 0;
  9.     char word[10], word1[10], word2[10];
  10.  
  11.     cout << "Enter How many time you want to do this .... \n";
  12.     cin >> j;
  13.     for (i = 1; i <= j; i++) {
  14.         cout << "\nEnter First Word\n";
  15.         cin >> word;
  16.         cout << "Enter Second Word\n";
  17.         cin >> word1;
  18.         cout << "Enter Third Word\n";
  19.         cin >> word2;
  20.  
  21.         cout << "\nGiven word is arranged in alphabetical order\n";
  22.         if (strcmp(word2, word1) && strcmp(word2, word)) {
  23.             cout << word2;
  24.             cout << "\n\n";
  25.         }
  26.         if (strcmp(word1, word) && strcmp(word1, word2)) {
  27.             cout << word1;
  28.             cout << "\n\n";
  29.         }
  30.         if (strcmp(word, word2) && strcmp(word, word1)) {
  31.             cout << word;
  32.         }
  33.         cout << "\n";
  34.         cout << "\t\t ****************** \n";
  35.     }
  36.     getch();
  37.     return 0;
  38. }
*************** *************** *************
Third program: it Suppose to solve this summation series :
1+2 - 3+4 - 5+6 ...... N
I do it like this

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #define N 3
  4.  
  5. main()
  6. {
  7.   int i,j,d=0,s=0; float sum = 0;
  8.   for (i=0; i <= N; i++){
  9.     sum +=((d-N)-(((d+i)+1)+((s+i)+2));
  10.     d=2+i;
  11.     s=2+i;
  12.       }
  13.   printf("%d:  %4.6f\n", i, sum);
  14.   getch();
  15. }
*************** *************** *************** ******
Fourth program : it ask the user to entered two word and exchange the first half a part from word the first string with the second half a part from word the second string also exchange the second half a part from first string with the first half a part string from the second .

I do it like this

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. main()
  5. {
  6.     int i, j;
  7.  
  8.     cout << "Enter How many time you want to do this a word";
  9.     cin >> j;
  10.     for (i = 1; i <= j; i++) {
  11.         cout << "\nEnter The Words\n";
  12.         char word1[6], word2[6], tmp[5], tmp1[5];
  13.         cin >> word1;
  14.         cin >> word2;
  15.         cout << "\nThe first word is ";
  16.         cout << word1;
  17.         cout << "\nThe second word is ";
  18.         cout << word2;
  19.         cout << " \n\n";
  20.         strcpy(tmp1, word2);
  21.         strncpy(word2, word1, 3);
  22.         cout << "\n";
  23.         cout << word2;
  24.         strcpy(tmp, word2);
  25.         strncpy(word1, tmp1, 3);
  26.         cout << "\n";
  27.         cout << " \n\n";
  28.         cout << word1;
  29.         cout << " \n\n";
  30.     }
  31.     getch();
  32. }
*************** *************** *************** *****
Fifth program: it Suppose to Generate 9 number and then 0,5
Example( a program Generate 055341122 it will be like this 0505341122 or like this 0555341122

I do it like this

Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<stdlib.h>
  4. main()
  5. {
  6.     int i, j, d = 0, k, tmp;
  7.     cin >> j;
  8.     while (d < j) {
  9.         for (i = 1; i <= 9; i++) {
  10.             k = 1 + rand() % 6;
  11.             cout << k;
  12.         }
  13.         tmp = k;
  14.         cout << tmp;
  15.         cout << "\n";
  16.         d++;
  17.     }
  18.     getch();
  19.     return 0;
  20. }
So help me plzzzzzzzzzzzzz zz
May 20 '07 #1
6 1345
AdrianH
1,251 Recognized Expert Top Contributor
I'm sorry, but although it would appear that you have written the code, you are not telling us anything about what is wrong. You have to tell us that before we even attempt to do anything as for all we know, this could be the assignment.


Adrian

EDIT: PS Please improve your indenting style. Some of these are unreadable.
May 20 '07 #2
logieen
6 New Member
in a first program i want it to enter full name word[10] ;
let's say the user enter " sasuke naruto gaara "
it Suppose to separate the name into first name " sasuke" i want it to store it in f[10] and the middle name " naruto" stored in m[10] and the last name"gaara" stored in l[10]
the program i post it work but does't do that
it enterd the full name but doesn't separate the name there the problem


-------------
second program it work but doesn't arranges the word in alphabetical order .there the problem

-------------------------
third program I know is totally wrong cause it Suppose to solve this summation series I tried so hard to solve it but doesn't work with me

1+2 - 3+4 - 5+6 ...... N



---------------------
fourth program it work let's say the user enter first word" sasuke " second word " naruto" the run will be like this " sasnar" and "narsas" when i want the run like this "ukesas"
"utonar"

-------------------
fifth program like I said it Suppose to Generate 9 number randomly and then add 0,5 where I colored it
Example( a program Generate 05341122 it will be like this 0505341122 or like this 0555341122


so help me am not that much in c and c++
May 20 '07 #3
AdrianH
1,251 Recognized Expert Top Contributor
Ok, so what results did you get?


Adrian
May 21 '07 #4
logieen
6 New Member
in a first program i want it to enter full name word[10] ;
let's say the user enter " sasuke naruto gaara "
it Suppose to separate the name into first name " sasuke" i want it to store it in f[10] and the middle name " naruto" stored in m[10] and the last name"gaara" stored in l[10]
the program i post it work but does't do that
it enterd the full name but doesn't separate the name there the problem
It just enter the full name it doesn't separate.


-------------
second program it work but doesn't arranges the word in alphabetical order .there the problem
this the run
http://www.el3mlak.net/up/images/5262412f.png


-------------------------
third program I know is totally wrong cause it Suppose to solve this summation series I tried so hard to solve it but doesn't work with me
1+2 - 3+4 - 5+6 ...... N

here the run show -45.000

---------------------
fourth program it work let's say the user enter first word" sasuke " second word " naruto" the run will be like this " sasnar" and "narsas" when i want the run like this "ukesas" "utonar"
this is the run
http://www.el3mlak.net/up/images/3893144f.png
-------------------
fifth program like I said it Suppose to Generate 9 number randomly and then add 0,5 where I colored it
Example( a program Generate 05341122 it will be like this 0505341122 or like this 0555341122
this is the run
http://www.el3mlak.net/up/images/7086157f.png
May 21 '07 #5
AdrianH
1,251 Recognized Expert Top Contributor
What compiler are you using? Did you change your programmes since you posted them?


Adrian
May 21 '07 #6
AdrianH
1,251 Recognized Expert Top Contributor
Ok, here is a list for the first one. When we get your first programme working, we will move on to the next.
  • main() should return an int
  • don’t include iostream.h, include iostream instead (no .h) and add the line using namespace std; after the includes.
  • you don’t (at least you shouldn’t) need to include ctype.h
  • don’t include conio.h as this is not portable. Instead of using getch();, use cin.ignore(); instead. It will wait until you press the enter key.
  • for your loop condition, use !cin.eof(). This means to continue looping while it has not reached the end of the stream. Using cin >> word doesn’t make sense as it returns an object, not a Boolean value.
  • cout.width(‘\0’ ) is not correct. Though it will compile, your use of it suggests that you do not know how to use it correctly. Read up on this function and others here.
  • you only have one place where you are reading in anything, and no condition to differentiate between the first, middle and last name. Either 1) make three different spots where you read in, or 2) use some sort of counter to differentiate.
Once you have fixed these problems, let me know how you are doing. If you are having other problems, please post back here and I will continue to help. If things go well, we can continue on with the next of your questions.


Adrian
May 21 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2757
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like storing products in
22
2285
by: Martin MOKREJ© | last post by:
Hi, I'm looking for some easy way to do something like include in c or PHP. Imagine I would like to have: cat somefile.py a = 222 b = 111 c = 9
9
2080
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash script that allows anyone to download, compile (with flags given by user) and install Python and some external modules (e.g. wxPython, PyGTK, Numeric...). I use Python every day and when new version of Python (or some external module) is released, I...
1
2609
by: Az Tech | last post by:
Hi people, (Sorry for the somewhat long post). I request some of the people on this group who have good experience using object-orientation in the field, to please give some good ideas for topics to include in a course on object-orientation that I'm going to conduct. (I will later summarize all the replies and discussion, for the
193
9648
by: Michael B. | last post by:
I was just thinking about this, specifically wondering if there's any features that the C specification currently lacks, and which may be included in some future standardization. Of course, I speak only of features in the spirit of C; something like object-orientation, though a nice feature, does not belong in C. Something like being able to #define a #define would be very handy, though, e.g: #define DECLARE_FOO(bar) #define...
1
1492
by: srikanth | last post by:
hi, I have one file it filled with some values in rows/colums. some times, some variables (in a particular row& column) may not be filled. depending on the kind its filled i will go for defferent kind of operations in my C-programm. with fgets and sscanf, i can get values in one line, but some times some particular row&column may be not filled. then how can my programm knows its not filled. means it cant take empty space as NaN(not a...
48
2179
by: yezi | last post by:
Hi, all: I want to record some memory pointer returned from malloc, is possible the code like below? int memo_index; int i,j; char *tmp; for (i=0;i<10;i++){
24
1719
by: Kevin | last post by:
Hey guys. I'm looking to get together some VB programmers on Yahoo messenger. I sit at a computer and program all day. I have about 3 or 4 people already, but it would be really cool to have a much larger list of people (for all of us to benefit). I have found it to be an invaluable resource to answer those hard or weird programming questions that come up. If you are interested, please reply, or send me an email at imgroup@gmail.com
21
1798
by: Jim | last post by:
I am trying to write an HTTP/HTTPS proxy server in VB.Net 2005. But, I don't really even know how the internal workings of a proxy should act. Does anyone have anything on the protocols used in handling requests by proxies? I have Googled my eyes out....and found nothing. (BTW, props to Google for refusing the ridiculous request for their search results.)
6
2347
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system (bash to be precise). All you need to know is that there are four classes. (Of course, you may...
0
9628
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9464
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10289
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10061
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9923
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7471
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6722
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4031
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3622
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.