GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 05-Feb-2004, 05:07
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough

Problem putting variables cumulatively into a string,


Im tryin to create a calculator where u can put the number in by typing or by press buttons. I have a problem when i try get the input of the buttons into the string. The code is very long and poor coz im not sure how to shorten it until i get everything sorted, so iv eft the chucks out of code that are just repeats of the above lines. How do i get a string to accept each term cumulatively so i can have a multi-digit number?

CPP / C++ / C Code:
#pragma windows 300000,500000,"cwp_ico.rc" 
#include <windows.h> 
#include <stdio.h> 

int number1=0,number2=0; 
double ans;
int One1(),Two1(),Three1(),Four1(),Five1(),Six1(),Seven1(),Eight1(),Nine1(),Zero1(); 
int One2(),Two2(),Three2(),Four2(),Five2(),Six2(),Seven2(),Eight2(),Nine2(),Zero2(); 
int Add(),Subtract(),Multiply(),Divide(),Close(); 
int main()

        { 
        winio("%bg%ca[Windows Calculator]&",RGB(255,100,100)); 
        winio("%fn[Paris]%ts First Number: %rd&",2.5,&number1); 
        winio("\tSecond Number: %rd\n&",&number2);
        winio("\t%ts%bc[grey]%`^bt[1]&",1.5,One1);
        winio("%bc[grey]%^bt[2]&",Two1);
        winio("%bc[grey]%^bt[3]&",Three1);
        winio("%bc[grey]%^bt[4]&",Four1);
        winio("%bc[grey]%^bt[5]&",Five1);
        winio("\t\t\t%bc[grey]%^bt[1]&",One2);
        winio("%bc[grey]%^bt[2]&",Two2);
        winio("%bc[grey]%^bt[3]&",Three2);
        winio("%bc[grey]%^bt[4]&",Four2);
        winio("%bc[grey]%^bt[5]&",Five2);
//repeated for all numbers but on a separate line//
        winio("\n%ts %bc[red]%^bt[+]\t&",2.0,Add);  
        winio("%bc[red]%^bt[-]\t&",Subtract); 
        winio("%bc[red]%^bt[*]\t&",Multiply); 
        winio("%bc[red]%^bt[/]\t&",Divide); 
        winio("%bf%ts  answer  %8rf&",3.0,&ans);
        winio("\n\t\t%ts  %bc[black]%^bt[%tc\t,Closeeeeeeeeeeeeeee]",2.0,Close); 
        }
       
        
int One1()
        {
        number1=1;
        return 1;
        }
int Two1()
        {
        number1=2;
        return 1;
        }
//repeated over until Zero1//
int One2()
        {
        number2=1;
        return 1;
        }
int Two2()
        {
        number2=2;
        return 1;
        }
//repeated over until Zero2//       
//start of processing//
int Add() 
        { 
        ans=number1+number2; 
        return 1; 
        } 
int Subtract() 
        { 
        ans=number1-number2; 
        return 1; 
        } 
int Multiply() 
        { 
        ans=number1*number2; 
        return 1; 
        } 
int Divide() 
        { 
        ans=number1/number2; 
        return 1; 
        }
int Close()
        {
        return 0; 
        }
Last edited by dsmith : 05-Feb-2004 at 07:24. Reason: Changed code keyword to c keyword
  #2  
Old 05-Feb-2004, 07:33
dsmith's Avatar
dsmith dsmith is offline
Senior Member
 
Join Date: Jan 2004
Location: Utah, USA
Posts: 1,351
dsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of lightdsmith is a glorious beacon of light
Quote:
Originally Posted by warny_maelstrom
How do i get a string to accept each term cumulatively so i can have a multi-digit number?

Hi Warny. I hate to answer a question with a question, but I am having a little trouble following what you are doing.

If you have a complete string that is a number, you can convert that entire string to a double (or long or int) by using on of the following
CPP / C++ / C Code:
int atoi(const char* string);
long atol(const char* string);
double atof(const char* string);

These are all defined in the stdlib.h header file. I am not sure if this helps or not as I had a little trouble figuring out your question.

Incidently, I am writing a library that will parse an entire string that I hope to post this weekend sometime. It is based upon the discussion in this thread. I am not sure if this is something that you would be interested in or not.

Anyway, good luck!
  #3  
Old 05-Feb-2004, 07:43
tay's Avatar
tay tay is offline
Junior Member
 
Join Date: Jan 2004
Posts: 77
tay will become famous soon enough
warny_maelstrom

i try to compile the program that u post at above
i not sure is my compile did not support ur code "winio"

what is winio ??
can u explain it to me
  #4  
Old 05-Feb-2004, 09:29
warny_maelstrom warny_maelstrom is offline
Junior Member
 
Join Date: Jan 2004
Posts: 41
warny_maelstrom will become famous soon enough
dsmith, im tryin to get so that when someone presses more than one button that iv created that i get a string of numbers as an input rather than just changing the original number. eg. user presses button[1], number 1 appears in the "First Number" box, then when they press button[4] only number 4 appears where as i would like 14 to appear and b the input once the user clicks the appropriate button.
At the moment it works fine if only suming 2 single digit numbers together but i really want to b able to use bigger numbers.

tay:-Iv only been doin programmin for a month or two so im not completely sure but its windows input output, i think it lets u open a windows box instead of the normal crap black dos-prompt type box that normally comes up when u run a program. Check if u have the windows.h program within ur libary coz that might b the problem, if u do take out the "#pragma windows 300000,500000,"cwp_ico.rc"" bit coz im not sure where this comes from i only know wot it does and its just aesthetics.
 
 

Recent GIDBlogToyota - 2008 September Promotion by Nihal

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 11:32.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.