|
Tabang wrote: ...pls help
Well in this half of the universe 24/6 = 4!
|
|
|
|
|
Tabang wrote: ...pls help
With what? You have a multi-step problem here. You could start with:
#include <string>
#include <iostream>
void main( void )
{
std::string strInput;
cout << "Input: ";
cin >> strInput;
}
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
DavidCrow wrote: std::string strInput;
I'm pretty sure that wouldn't work with Turbo C[^]
|
|
|
|
|
Details, details.
On an unrelated note, it's been 19 years since I used Turbo C. That was a fun product.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Oh, I'm pretty sure David can do that with Turbo C .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
pls help me with the separation of commas from the set of numbers ...its hard
|
|
|
|
|
i guess... pls help me separate the commas from the numbers so i can calculate the average... it hard to separate it when im just a bigginer.. pls
|
|
|
|
|
Thanks. your codes are c++ i think?
|
|
|
|
|
It's not their fault. Actually, the people here are such experts that they can write a turbo c compiler in less time than what it would take for them to figure out if cout/cin or std::string is a C-language feature or not. They have risen much higher than the realms of specific programming languages. They only understand the language of bits and bytes and in their mind, both string and char are just a piece of f* memory holding some bits.
|
|
|
|
|
And what's your trouble about?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I know what you want. Just tell me if I am correct.
int main(void)
{
int a,b,c;
scanf("%d,%d,%d",&a, &b, &c);
printf("\nYou just entered: %d, %d, %d", a, b, c);
}
Pay special attention to the commas used inside the scanf function. I think it addresses your doubt to some extent. I had this doubt all my life.
Second, I suppose you will say that above program is very rigid as it allows input of only 3 variables. What if the no. of variables is not known.
Very valid question, I say. Only I have forgotten how to work with console and it give me creeps to find out about gets etc. See this [^]
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main(void)
{
char input[255];
int sum = 0;
int num = 0;
gets(input);
char* token;
token = strtok(input, ",");
while (token != NULL)
{
sum += atoi(token);
++ num;
token = strtok(NULL, ",");
}
printf("\nSum = %d, average = %f\n", sum, (num==0? 0 : (float)sum/num));
return 0;
}
Hope it helps?
|
|
|
|
|
THANK YOU SO MUCH.. it really helpes...cool...
|
|
|
|
|
(num==0? 0 : (float)sum/num)
what does this code do?..... is there any other alternative in finding the average i mean other formula..pls reply
|
|
|
|
|
Can you tell what is the conditional or ternary operator [? :] in C and how does it work? Any example that can help me in understanding it?
Answer my question and i will answer yours.
|
|
|
|
|
can anyone help me on this code. im trying to input a hindu arabic number in a text file input.txt then it will output a conversion of that number into roman numeral... but the problem is it wont output the convertion.. the out put are trash characters.... but this worked when i was not inputting in a notepad .it worked when i was inputting in the running turbo c... here are my codes...... the first one is when the inputs are still in c and the other is in a .txt file....
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp;
int a;
char base[2];
int i,x;
char str[50];
char c;
int counter=0;
do
{
clrscr();
if(counter!=0)
{
for(i=0;str[i]!=NULL;i++)
str[i]=' ';
}
printf("\nEnter a number from 1 to 3999 only: ");
scanf("%d",&a);
fp = fopen("c:\output.txt","a+");
fprintf(fp,"\n\nHindu Arabic: %d",a);
if(a<=0 || a>=4000)
{
printf("out of range");
fprintf(fp,"\t\tOut of range!!!!");
goto exit;
}
i=0;
while(a!=0)
{
if(a>=1 && a<4)
{
base[0] = 'I'; base[1] = ' ' ; a = a-1;
}
else if(a>=4 && a<5)
{
base[0] = 'I'; base[1] = 'V'; a = a-4;
}
else if(a>=5 && a<9)
{
base[0] = 'V'; base[1] = ' '; a = a-5;
}
else if(a>=9 && a<10)
{
base[0] = 'I'; base[1] = 'X'; a = a-9;
}
else if(a>=10 && a<40)
{
base[0] = 'X'; base[1] = ' '; a = a-10;
}
else if(a>=40 && a<50)
{
base[0] = 'X'; base[1] = 'L'; a = a-40;
}
else if(a>=50 && a<90)
{
base[0] = 'L'; base[1] = ' '; a = a-50;
}
else if(a>=90 && a<100)
{
base[0] = 'X'; base[1] = 'C'; a = a-90;
}
else if(a>=100 && a<400)
{
base[0] = 'C'; base[1] = ' '; a = a-100;
}
else if(a>=400 && a<500)
{
base[0] = 'C'; base[1] = 'D'; a = a-400;
}
else if(a>=500 && a<900)
{
base[0] = 'D'; base[1] = ' '; a = a-500;
}
else if(a>=900 && a<1000)
{
base[0] = 'C'; base[1] = 'M'; a = a-900;
}
else if(a>=1000 && a<4000)
{
base[0] = 'M'; base[1] = ' '; a = a-1000;
}
else
{
base[0] = ' '; base[1] = ' ';
}
str[i]=base[0];
str[i+1]=base[1];
i+=2;
}
printf("\n\n\nThe number converted into roman numerals is: ");
fprintf(fp,"\t\tRoman Numeral:");
for(i=0;str[i]!=NULL;i++)
{
if(str[i]!=';' && str[i]!=' ')
printf("%c",str[i]);
fprintf(fp,"%c",str[i]);
}
exit:
printf("\n\n\n\nPress any key to continue or space to exit... ");
fclose(fp);
c = getch();
counter++;
}while(c!=' ');
}
heres the one that inputs in a notepad and is not working
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp,*fp2;
int a;
char base[2];
int i,x;
char str[50];
char c;
int counter=0;
do
{
clrscr();
if(counter!=0)
{
for(i=0;str[i]!=NULL;i++)
str[i]=' ';
}
fp = fopen("c:\output.txt","a+");
fp2= fopen("c:\input.text","r");
while(!feof(fp)){
i=0;
fscanf(fp2,"%d",&a);
if(a>=0 && a<=3999)
{
fscanf(fp2,"%d",&a);
if(a>=1 && a<4)
{
base[0] = 'I'; base[1] = ' ' ; a = a-1;
}
else if(a>=4 && a<5)
{
base[0] = 'I'; base[1] = 'V'; a = a-4;
}
else if(a>=5 && a<9)
{
base[0] = 'V'; base[1] = ' '; a = a-5;
}
else if(a>=9 && a<10)
{
base[0] = 'I'; base[1] = 'X'; a = a-9;
}
else if(a>=10 && a<40)
{
base[0] = 'X'; base[1] = ' '; a = a-10;
}
else if(a>=40 && a<50)
{
base[0] = 'X'; base[1] = 'L'; a = a-40;}
else if(a>=50 && a<90)
{
base[0] = 'L'; base[1] = ' '; a = a-50;
}
else if(a>=90 && a<100)
{
base[0] = 'X'; base[1] = 'C'; a = a-90;
}
else if(a>=100 && a<400)
{
base[0] = 'C'; base[1] = ' '; a = a-100;
}
else if(a>=400 && a<500)
{
base[0] = 'C'; base[1] = 'D'; a = a-400;
}
else if(a>=500 && a<900)
{
base[0] = 'D'; base[1] = ' '; a = a-500;
}
else if(a>=900 && a<1000)
{
base[0] = 'C'; base[1] = 'M'; a = a-900;
}
else if(a>=1000 && a<4000)
{
base[0] = 'M'; base[1] = ' '; a = a-1000;
}
else { base[0] = ' '; base[1] = ' '; }
str[i]=base[0];
str[i+1]=base[1];
i+=2;
}
fprintf(fp,"\nRoman Numeral:");
for(i=0;str[i]!=NULL;i++)
{
if(str[i]!=';' && str[i]!=' ')
printf("%c",str[i]);
fprintf(fp,"%c",str[i]);
}goto exit;
}
exit:
printf("\n\n\n\nPress any key to continue or space to exit..");
fclose(fp);
c = getch();
counter++;
}while(c!=' ');
}
please can anyone help?
|
|
|
|
|
Tabang wrote: please can anyone help?
So when you step through this code using the debugger (you are doing that, aren't you?), what do you see?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
No surprise, since the latter program is a bad porting of the former one. Try
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main()
{
FILE *fp, *fpi;
int a;
char base[2];
int i,x;
char str[50];
char c;
int counter=0;
fpi = fopen("input.txt","r");
fp = fopen("output.txt","a+");
if (!fp || !fpi) return;
while (!feof(fp))
{
if(counter!=0)
{
for(i=0;str[i]!=NULL;i++)
str[i]=' ';
}
if (fscanf(fpi, "%d",&a) != 1) break;
fprintf(fp,"\n\nHindu Arabic: %d",a);
if(a<=0 || a>=4000)
{
printf("out of range");
fprintf(fp,"\t\tOut of range!!!!");
goto exit;
}
i=0;
while(a>0)
{
if(a>=1 && a<4)
{
base[0] = 'I'; base[1] = ' ' ; a = a-1;
}
else if(a>=4 && a<5)
{
base[0] = 'I'; base[1] = 'V'; a = a-4;
}
else if(a>=5 && a<9)
{
base[0] = 'V'; base[1] = ' '; a = a-5;
}
else if(a>=9 && a<10)
{
base[0] = 'I'; base[1] = 'X'; a = a-9;
}
else if(a>=10 && a<40)
{
base[0] = 'X'; base[1] = ' '; a = a-10;
}
else if(a>=40 && a<50)
{
base[0] = 'X'; base[1] = 'L'; a = a-40;
}
else if(a>=50 && a<90)
{
base[0] = 'L'; base[1] = ' '; a = a-50;
}
else if(a>=90 && a<100)
{
base[0] = 'X'; base[1] = 'C'; a = a-90;
}
else if(a>=100 && a<400)
{
base[0] = 'C'; base[1] = ' '; a = a-100;
}
else if(a>=400 && a<500)
{
base[0] = 'C'; base[1] = 'D'; a = a-400;
}
else if(a>=500 && a<900)
{
base[0] = 'D'; base[1] = ' '; a = a-500;
}
else if(a>=900 && a<1000)
{
base[0] = 'C'; base[1] = 'M'; a = a-900;
}
else if(a>=1000 && a<4000)
{
base[0] = 'M'; base[1] = ' '; a = a-1000;
}
else
{
base[0] = ' '; base[1] = ' ';
}
str[i]=base[0];
str[i+1]=base[1];
i+=2;
}
str[i]='\0';
fprintf(fp,"\t\tRoman Numeral:");
for(i=0;str[i]!='\0';i++)
{
if ( str[i] != ' ')
{
fprintf(fp,"%c",str[i]);
}
}
exit:
counter++;
}
fclose(fp);
fclose(fpi);
}
BTW: In both programs you missed to zero-terminate the string str .
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
modified on Friday, October 9, 2009 6:16 PM
|
|
|
|
|
thanks so much for that, but the c would become assigned and not used... what should be done?
|
|
|
|
|
thanks so much for that ops it worked i erased the do statement...sorry about that.....Thanks..... what should i do i the input of that one will be a set off numbers and separater by comma?... and the average of that set number will be that one that is converted into Roman numerals?
pls help
|
|
|
|
|
Hi,
I have a class that handle .html files but the file that came to me is a .doc, so, i whould like to convert it to .html
There´s a .dll or .exe or classes for compiling ?
Tanks for your help.
|
|
|
|
|
How about Google[^]? The first hit[^] seems promissing already.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
You can use Word Automation to open the .doc file and save it as a .html file. After importing Word's type library, it's about 5 lines of code.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
Hi all,
I am new in MFC.
I am struggling with one of my system's modules which is I need to edit filed's value in the data source depending on some variables.
My problem is I stuck with Recordset type because I making the editting via SQL statment and the following which are I done so far:
CDatabase DBDecaying;
CString SqlRulesDecaying;
CString sDriver("MICROSOFT ACCESS DRIVER (*.mdb)");
CString sDsn;
CString ssDSN("ODBC;DRIVER={%s};DSN='';DBQ=%s");
CString sFile("c:\\DB\\db.mdb");
sDsn.Format(ssDSN, sDriver, sFile);
DBDecaying.Open(NULL,false,false,sDsn);
CRecordset RecSetRulesDecaying( &DBDecaying );
int X=2,Y=3;
double NewActiLevel = 0;
SqlRulesDecaying.Format(_T("update Rules set RActiLevel=%f where CNum=%d and
RNum=%d"),NewActiLevel,X,Y);
RecSetRulesDecaying.Open(CRecordset::forwardOnly,SqlRulesDecaying,CRecordset::??????);
Regarding the first parameter I tried snapshot,dynaset and dynamic instead of forwardonly. nothing happens.
So what I should put insted of ???? I tried (Update,Can Update,..) but I had syntax errors.
So please any help will be appreciated.
Best regards.
|
|
|
|
|
moh.hijjawi wrote: Regarding the first parameter I tried snapshot,dynaset and dynamic instead of forwardonly. nothing happens.
Since CRecordset::forwardOnly is a read-only recordset, that would be the one to not choose. Any of the others should work.
moh.hijjawi wrote: So what I should put insted of ????
CRecordset::none should be sufficient.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
|
|
|
|
|
First of all thank you.
I did like you mentioned but i have an error which is "Attempt to open a table failed- there is no columns to retrieve were specified" and I sure that the sql it is OK;
please any help
|
|
|
|