If I am writing a C++ program that waits for a user to input some command and th
ID: 3665591 • Letter: I
Question
If I am writing a C++ program that waits for a user to input some command and then two numbers in the formfunc(num1, num2)
as a line of text in the console, how can I process this to save num1 and num2 to variables so I can run the command with those two number parameters? I am able to do a string compare in an if statement to get to the desired command but num1 and num2 are never properly set to local variables. I have tried several ideas but the parenthesis and comma keep throwing it off.
Thanks in advance! If I am writing a C++ program that waits for a user to input some command and then two numbers in the form
func(num1, num2)
as a line of text in the console, how can I process this to save num1 and num2 to variables so I can run the command with those two number parameters? I am able to do a string compare in an if statement to get to the desired command but num1 and num2 are never properly set to local variables. I have tried several ideas but the parenthesis and comma keep throwing it off.
Thanks in advance! If I am writing a C++ program that waits for a user to input some command and then two numbers in the form
func(num1, num2)
as a line of text in the console, how can I process this to save num1 and num2 to variables so I can run the command with those two number parameters? I am able to do a string compare in an if statement to get to the desired command but num1 and num2 are never properly set to local variables. I have tried several ideas but the parenthesis and comma keep throwing it off.
Thanks in advance!
func(num1, num2)
as a line of text in the console, how can I process this to save num1 and num2 to variables so I can run the command with those two number parameters? I am able to do a string compare in an if statement to get to the desired command but num1 and num2 are never properly set to local variables. I have tried several ideas but the parenthesis and comma keep throwing it off.
Thanks in advance!
Explanation / Answer
//program to do in turbo C++ IDE by taking two numbers from the user
//numbers.cpp
#include<iostream.h>
#include<conio.h>
class Test
{
private:
int number1,number2; //instance variables
public:
void func(int n1,int n2) //n1 and n2 are local variables
{
number1=num1;
number2=num2;
cout<<" Number 1 is"<<number1;
cout<<" Number 2 is"<<number2;
}
};
int main()
{
Test t;
int num1,num2;
cout<<" Enter the num1";
cin>>num1;
cout<<" Enter the num2 ";
cin>>num2;
t.func(num1,num2);
getch();
return 0;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.