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
A company wants to build a new type of spaceship for transporting astronauts to the moon. What should the company do first?
Paraphin [41]

Answer:

Think of some ideas of how their gonna create the new spaceship

Explanation:

Because I'm Smort (typo intended)

4 0
3 years ago
Read 2 more answers
Given the strings s1 and s2 that are of the same length, create a new string consisting of the first character of s1 followed by
LiRa [457]

Answer:

s1='abc'

s2='wxyz'

length=len(s1)

s3=''

for i in range(length):

   s3+=s1[i]+s2[i]

print(s3)

3 0
4 years ago
A user complains that her computer is performing slowly. She tells you the problem started about a week ago when new database so
motikmotik

Answer/Explanation:

It is best to use Performance Monitor and Process counters to observe performance.

Cheers

6 0
3 years ago
Which commas is used to combine two or more cells together into one cell
AURORKA [14]
The command is Merge & Center
This command could be easily found in the toolbar of your excel.
If you execute this command in two different cells, those cells will be merged into one larger cell and the content in that cells will be placed exactly in the middle of the combined cell (measures according to combined cells' length)
5 0
3 years ago
Points!!!!!!!! pls help
siniylev [52]
D. Rasterize

This answer makes the most since
7 0
3 years ago
Read 2 more answers
Other questions:
  • A software program that enables users to find and display information stored as html pages on the internet is a(n) ____.
    5·1 answer
  • A/an ___________ is a scheduling tool that sets the standard and nonworking time for the project and is used to assess how tasks
    6·1 answer
  • What term is defined as private data placed in a packet with a header containing routing information that allows the data to tra
    13·1 answer
  • Networks that are designed to connect similar computers that share data and software with each other are called:
    10·1 answer
  • write the program or pseudocode algorithm that computes the product and average of three integers and display the results​
    7·1 answer
  • What number system that has 16 numerals
    11·2 answers
  • For each part create a vector n in which the first element is 1, the increment is 1 and the last term is 5, 50, or 5,000. Then u
    13·1 answer
  • Which of the following is a web app?
    5·1 answer
  • Create a spreadsheet that lists the ten currencies you chose. For each currency, enter an amount and create a
    12·1 answer
  • Question # 1 Multiple Select Which of the following shows the assignment of a string to a variable? Select 3 options. answer = "
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!