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]
2 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]2 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
What data unit is encapsulated inside a packet?
viva [34]

Answer: datagram

Explanation:

7 0
3 years ago
Read 2 more answers
Data with values that change continuously or smoothly over time is known as:
Alexeev081 [22]

Answer:

A.  \:  \boxed{analog  \: data}

5 0
3 years ago
Read 2 more answers
What shoul i get, Airpods or a ps4 cooling fan ???
Fynjy0 [20]

Answer:

Airpods, there is ps5 coming out

Explanation:

3 0
2 years ago
Read 2 more answers
Ark titanoboa taming
ivann1987 [24]
Huh???????................
3 0
3 years ago
Passwords are usually alphanumeric and usually cannot contain spaces or ________.
vlada-n [284]

Answer:

The answer is A. Punctuation.  A password can contain symbols

Explanation:

3 0
2 years ago
Read 2 more answers
Other questions:
  • An organization uses SAP financial management software to store accounting details and Microsoft CRM software to record customer
    12·1 answer
  • Harold included an excerpt from an Internet magazine in an article he wrote for the school newspaper. However, he did not ask pe
    13·2 answers
  • EXCEL 2016:
    8·2 answers
  • Jason is working on a project that requires him to manage a huge amount of data. The spreadsheet he is working on has data relat
    10·1 answer
  • Explain the importance of mobile computing in communication​
    5·1 answer
  • Which of the following is the process of writing the step-by-step instructions that can be understood by a computer?
    5·1 answer
  • Your task is to identify three or more ways that big data is being collected on a regular basis, including one data collection m
    9·1 answer
  • You are setting up a small network. The customer has decided to change his internet service provider (ISP) to EtherSpeed. The IS
    9·1 answer
  • There are many reasons to convert to the decimal numbering system. Select the best answer. When checking numeric values in compu
    5·2 answers
  • A researcher is interested in learning more about the different kinds of plants growing in different areas of the state she live
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!