1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
madreJ [45]
3 years ago
6

Write a function that converts a string into an int. Assume the int is between 10 and 99. Do not use the atoi() or the stoi() fu

nction.
Computers and Technology
1 answer:
Liula [17]3 years ago
6 0

Answer:

Written in C++

#include <iostream>

#include <sstream>

using namespace std;

int main()  {

   string num;

   cout<<"Enter a number: ";

   cin>>num;

   stringstream sstream(num);

   int convertnum = 0;

   sstream >> convertnum;

   cout << "Output: " << convertnum;

}

Explanation:

Without using atoi() or stoi(), we can make use of a string stream and this is explained as follows:

This line declares a string variable num

   string num;

This line prompts user for input

   cout<<"Enter a number: ";

This line gets user input

   cin>>num;

This line declares a string stream variable, sstream

   stringstream sstream(num);

This line declares and initializes the output variable, convertnum to 0

   int convertnum = 0;

The stream is passed into the output variable, convertnum

   sstream >> convertnum;

This line displays the output

   cout << "Output: " << convertnum;

<em>Note that: if user enters a non integer character such as (alphabet, etc), only the integer part will be convert.</em>

<em>For instance,</em>

<em>40a will be outputted as 40</em>

You might be interested in
Factoring of integers. Write a python program that asks the user for an integer and then prints out all its factors. For example
Oduvanchick [21]

num = int(input("Enter a number: "))

i = 2

while num > 1:

   if num % i == 0:

       num = num / i

       print(i, end=" ")

       i = 2

   i += 1

I hope this helps!

8 0
3 years ago
¿En qué año se funda lego?
pochemuha
August 10, 1932 in Billund, Denmark
7 0
3 years ago
1. Answer the following questions: a. What are the different types of number system? Name them.​
BigorU [14]

Answer:

binary,decimal, hexadecimal and octal number system

5 0
3 years ago
After purchasing new computers for her​ department, a manager is now comparing the performance of the new computers to the compu
AlladinOne [14]

Answer:

evaluation of decision effectiveness

Explanation:

Based on the information provided within the question it can be said that in this scenario she is in the stage of evaluation of decision effectiveness. This is the stage after the decision has been made in which the individual begins to analyze the decision and determine whether the decision was as effective as originally anticipated , and whether or not it was the correct decision.

8 0
3 years ago
Which of the following scenarios might indicate that you have been a victim of identity theft?A)Your credit report displays acco
victus00 [196]

Answer:

Option A is the correct answer for the above question.

Explanation:

A Victim is a person, who faces the problem of a criminal person. Here in the question, the scenario is that a user is a victim of the identity of being theft by some other person. So the user can get known by the help of option a, which suggests that the user's credit card report display something which is not done by him then it can be the scenario, where the user can understand that he is a victim. hence option a is the correct answer where the other option is not because--

  • Option B suggests the user does not pay the bill on time but it is a general case because the bill is paid by the user is in every month not a single time.
  • Option C suggests both options (A and B) are correct, but option b is not the correct.
  • Option D suggests that no option is valid from the above but option A is the correct.
7 0
3 years ago
Other questions:
  • To join two or more objects to make a larger whole is to _____________ them.
    8·2 answers
  • How to remove a channel from favorite list on suddenlink?
    15·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    11·1 answer
  • Explain what occurs when you synchronize computer and mobile devices.
    5·1 answer
  • Design a hierarchy c hart or flowchart for a program that calculates the current balance in a savin gs account. The program must
    8·1 answer
  • 1. What are you going to do if someone ask for your personal information online?​
    12·2 answers
  • Which of the following statements is FALSE?
    5·1 answer
  • State differences between title bar and menu bar​
    5·1 answer
  • Who know's web Design
    12·1 answer
  • Write program to read 10 random numbers, then find how many of them accept division by 4,
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!