Can not figure out how to fix my errors

I have been trying to debug my code for hours. I have gone from 43 errors down to 19 errors. I am very new to C++ and would appreciate any help.

Create a program to determine the largest number out of 15 numbers entered (numbers entered one at a time). This should be done in a function using this prototype:

double larger (double x, double y);

Make sure you use a for loop expression inside your function.

Enter 15 numbers
11 67 99 2 2 6 8 9 25 67 7 55 27 1 1
The largest number is 99

Hints:
Read the first number of the data set. Because this is the only number read to this point, you may assume that it is the largest number so far and call it max.
Read the second number and call it num. Now compare max and num, and store the larger number into max. Now max contains the larger of the first two numbers.
Read the third number. Compare it with max and store the larger number into max.
At this point, max contains the largest of the first three numbers. Read the next number, compare it with max, and store the larger into max.




Here is my code:

// RSWA1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <string>
#include <istream>
#include <sstream>
#include <ctime>
#include <ostream>
#include <fstream>

double larger(double x, double y);



int main()
{
const int N = 15;

std::cout << "Please, enter " << N << " numbers, one at a time,\n"
"and the program will return the largest number.\n";

double number;

std::cout << "Enter the first number: ";
std::cin >> "11";

double largest_so_far = 11;

for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "67";

largest_so_far = larger(largest_so_far, 67);

for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "99";

largest_so_far = larger(largest_so_far, 99);

for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "2";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "2";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "6";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "8";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "9";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "25";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "67";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "7";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "55";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "27";

largest_so_far = larger(largest_so_far, 99)

;for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "1";

largest_so_far = larger(largest_so_far, 99)

; for (int i = 1; i < N; ++i)
{
std::cout << "Enter another number: ";
std::cin >> "1";

largest_so_far = larger(largest_so_far, 99)

; for (int i = 1; i < N; ++i)
{

std::cout << "The largest number is: " << largest_so_far << '\n';
}

double larger(double x, double y) { return x < y ? y : x }
}

return 0;
}





My errors:
C2678 binary '>>': no operator found which takes a left hand operand of type 'std::istream', (or there is no acceptable conversion) keeps coming up

expected a ';' to go somewhere is this line double larger(double x, double y) { return x < y ? y : x }

my '}' at the very end of my code says it expects a '}'



Please use code tag so that it is easier to read your code. I am not sure you are suppose to hard code your numbers 11 67 99 2 2 6 8 9 25 67 7 55 27 1 1, because if you want to make this program run for other numbers for example: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 this code would be useless. What I would suggest you to do for this function is making the double x parameter as the user input and double y parameter as the max of all the numbers the user has input. I also see that you do not have a function definition, you have everything inside main, which defeats the purpose of having a function to compare the numbers.
Last edited on
std::cin >> "11";
You need a variable to hold an input from cin.
closed account (48T7M4Gy)
Hopefully you learn something out of this (substantial) reduction in your code, a couple of slight but important changes and the incorporation of the comments you have already received. You still need to add at least one line :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// RSWA1.cpp : Defines the entry point for the console application.
//

#include <iostream>

double larger(double x, double y);

int main()
{
    const int N = 3;
    
    std::cout << "Please, enter " << N << " numbers, one at a time,\n"
    "and the program will return the largest number.\n";
    
    double number;
    
    std::cout << "Enter the first number: ";
    std::cin >> number;
    
    double largest_so_far = number;
    
    for (int i = 1; i < N; ++i)
    {
        std::cout << "Enter another number: ";
        std::cin >> number;
        
        largest_so_far = larger(largest_so_far, number);
    }
    
    return 0;
}

double larger(double x, double y) { return x < y ? y : x; }
wow thank you everyone for your help! I am sorry I did not use code tag. I will for my next questions. So I made my code too long? The question asked me to use those numbers specifically so I was confused. Again I am very new to this so please do not look down upon me. Thank you for the code rewrite. I originally had a code written similar to that but when I built it, it only came up with Enter 15 numbers. So I thought my code was too short and I was supposed to use all the numbers in the question.
closed account (48T7M4Gy)
wow thank you everyone (sic) for your help!

Well, Rsimmins , you were obviously having a lot of trouble with it and that's why I suggested you make it a learning experience by reading the sample code carefully and make sure you understand each step line by line. Don't worry too much about "std::" you can use "using namespace std;" if you want.

As far as the numbers are concerned, just run the program and type them in at the prompt. Who knows, you might find I've made a blooper.

Your code is far too long! Just imagine how long it would have been if you had to analyze 10,000 numbers :)

Just think if you had a variable and associated cin, the program could ask the user for as many numbers at a time that they want.
Topic archived. No new replies allowed.