Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C programming problem
New Posts  All Forums:Forum Nav:

C programming problem

post #1 of 7
Thread Starter 
is there anyway to make this application add more then 2 values?? here is the source for the application

#include
#include
#include

int main(){

int sum1;
int sum2;
char addition;

while(true){

printf("Please enter your values::\n");
printf("if you wish to exit type 0X0\n");
scanf("%d%c%d",&sum1,&addition,&sum2);

if(addition == '+'){
printf("%d+%d=%d",sum1,sum2,sum1+sum2);
}


if(addition == '/'){
printf("%d/%d=%d",sum1,sum2,sum1/sum2);
}

if(addition == '*'){
printf("%d*%d=%d",sum1,sum2,sum1*sum2);
}

if(addition == '-'){
printf("%d-%d=%d",sum1,sum2,sum1-sum2);

}

if(addition == 'X'){
return 0;
}


}

getch();
system("cls");
}
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
post #2 of 7
Thread Starter 
whoops its suppose to be

#include
#include
#include
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
post #3 of 7
Thread Starter 
"iostream"
"stdio.h"
"conio.h"
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
post #4 of 7
You want to be able to parse something like "2+3+4"?
Old rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570K Asus Maximus V Gene MSI Radeon R9 280X Gaming G.Skill Trident 2400 C10 
Hard DriveHard DriveCoolingCooling
Crucial M500 240 Hitach HDT721010 EK Supremacy Clear CSQ Alphacool XT45 360+240 
CoolingCoolingMonitorPower
EK-VGA Supreme HF Swiftech MCP655 Asus MX239H Antec TP 550 New 
CaseAudio
NZXT Switch 810 Black M Creative X-Fi Extreme 
  hide details  
Reply
Old rig
(17 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core i5 3570K Asus Maximus V Gene MSI Radeon R9 280X Gaming G.Skill Trident 2400 C10 
Hard DriveHard DriveCoolingCooling
Crucial M500 240 Hitach HDT721010 EK Supremacy Clear CSQ Alphacool XT45 360+240 
CoolingCoolingMonitorPower
EK-VGA Supreme HF Swiftech MCP655 Asus MX239H Antec TP 550 New 
CaseAudio
NZXT Switch 810 Black M Creative X-Fi Extreme 
  hide details  
Reply
post #5 of 7
pretty easy...if you want to add an undetermined amount of integers together...use a while loop and an array for storage during the input process....then simply iterate through the array to sum up all of the elements.
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
Black Silence
(15 items)
 
  
CPUMotherboardRAMHard Drive
i5 3570k @ 4.5 GHz Asus P8Z77-M Pro Kingston HyperX Genesis 8 GB - 1600 MHz Seagate Barracuda 250 GB 
Optical DriveCoolingOSMonitor
Samsung WriteMaster Noctua NH-D14 Windows 10 ASUS VS24AH-P 
KeyboardPowerCaseMouse
Logitech Navigator Enermax Infiniti 650W Fractal R3 Black Pearl Razer Death Adder 
Mouse PadAudio
SteelSeries QcK Mass Altec Lansing FX4021 
  hide details  
Reply
post #6 of 7
Thread Starter 
i will try that i never thought of that thanks
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
post #7 of 7
Thread Starter 
yes
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
My computer
(18 items)
 
  
CPUMotherboardGraphicsRAM
Intel Core 2 Duo E6600 DG965SS powercolor 6670   
RAMHard DriveOptical DriveCooling
G.Skill Seagate  DVD WRITER heat sink + fan 
OSOSOSMonitor
Windows 7 Windows XP Linux Ubuntu FLATRON L1740B 
KeyboardPowerCaseMouse
Microsoft Basic 500 WATT PSU TOWER Microsoft Basic 
AudioOther
IDT intergrated AUDIO 5.1 speakers 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › C programming problem