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
Ron is in the process of designing tables for a database that will contain information for all school matches played in a year.
solong [7]
Primary Key, if we define field as primary key it will not accept duplicate values.<span>
</span>
6 0
3 years ago
The figure above shows a DC motor that contains a series field winding (F1) with a resistance of 10 , a parallel field winding (
shtirl [24]
Soooooooooooooooo you need to click c to get the right answer

 
5 0
3 years ago
Read 2 more answers
Write a program that displays, 10 numbers per line, all the numbers from 100 to 200 that are divisible by 5 or 6, but not both.
FromTheMoon [43]

Answer & Explanation:

To print 10 on a line and each number separated by space; you make the following modifications.

print(str(i)+" ",end=' ')

str(i)-> represents the actual number to be printed

" "-> puts a space after the number is printed

end = ' ' -> allows printing to continue on the same line

if(count == 10):

     print(' ')

The above line checks if count variable is 10;

If yes, a blank is printed which allows printing to start on a new line;

The modified code is as follows (Also, see attachment for proper indentation)

count = 0

for i in range(100,201):

     if(i%6 == 0 and i%5!=0) or (i%5 ==0 and i%6!=0):

           print(str(i)+" ",end=' ')

           count = count + 1

           if(count == 10):

                 print(' ')

                 count = 0

7 0
4 years ago
A communications objective is:?
creativ13 [48]
D. For example, if your ad is about cigars and it is targeted to 5-year-old girls who just want a doll, then you're not going to get a lot of sales.
5 0
4 years ago
In two-dimensional arrays, the _____________ is always listed second.
Sav [38]

Answer:

row

Explanation:

3 0
2 years ago
Other questions:
  • What are the changes in ios 14.2? What are the benefits of the ios developer program? What is next for Apple? Base your answers
    14·1 answer
  • What are the different components of the cloud architecture? The of the cloud architecture is the cloud, which is a collection o
    11·1 answer
  • Write an application that displays a series of at least five student ID numbers (that you have stored in an array) and asks the
    5·1 answer
  • Calculate the average of a set of grades and count
    9·1 answer
  • An object is suspended in a wind tunnel and the force measured for various levels of wind velocity: v (m/s) 10 20 30 40 50 60 70
    10·1 answer
  • A(n) ____ occurs when a situation results in service disruptions for weeks or months, requiring a government to declare a state
    6·1 answer
  • What can always be seen in the styles gallery??
    12·1 answer
  • Describe the three essential characteristics of an object fromthe perspective of object oriented paradigm.
    7·1 answer
  • Classify the following skills: communication, creativity, and independence.
    15·1 answer
  • Join for a pack battle loud microphone.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!